FAQ Database Discussion Community


Script works with ./file_name, but I get error when I start it using sh file_name

linux,bash,scripting
Script works with ./file_name, but I get error when I start it using sh file_name #!/bin/bash echo "Scenarijus, kuris is teksto failo paima pirmoje eiluteje esancius zodzius ir sukuria naujus katalogus tokiais paciais pavadinimais, jusu pasirinktame kataloge" echo " Scenarijus sukurtas: Tomas Vilemaitis " echo " " echo "Iveskite teksto...

Can I set specific numbers in bash instead of a sequence?

linux,bash,variables,scripting
I'm currently trying to make a script in bash that uses some specific numbers. It's for a different program but for the example, I'll use this basic ping script. In this example, the script would ping 192.168.1.215, 216, etc. up to 225 for i in `seq 215 225`; do ping...

Finding the average of a column excluding certain rows using AWK

linux,bash,awk,scripting
I want to calculate the average of the 5th column (last column) excluding the rows with the value "9999". Would appreciate your feedback. 77.300 16 1 3.6112914285714268 9.4 77.300 16 2 -0.001737142857145102 20.0 77.300 16 3 5.1570742857142857 8.9 77.300 17 0 3.6112914285714268 8.9 77.300 17 1 2.9484342857142849 11.7 77.300 17...

Get Last Modified Date for a script Deployment in NetSuite

scripting,netsuite
How do I get the last modified date of a deployment script? This can neither be searched with a saved Search nor it is available in the records browser.

Precompile script into objects inside C++ application

c++,scripting,compilation
I need to provide my users the ability to write mathematical computations into the program. I plan to have a simple text interface with a few buttons including those to validate the script grammar, save etc. Here's where it gets interesting. These functions the user is writing need to execute...

Bash script unexpected result for while loop

linux,bash,shell,scripting
I have following bash script to stop Apache server. I am not getting error but an unexpected result. #!/bin/bash /etc/init.d/httpd stop if [[ $? -ne 0 ]] then exit 1 fi RTN=10 while [[ $RTN -gt 0 ]] echo "Before" $RTN do sleep 5 RTN=`ps -C httpd | wc -l`...

What is the meaning of pwd|sed -e?

linux,shell,sed,scripting
I found the below snippet at the .sh file of my project to define some path : PGMPATH=`pwd|sed -e "s#/survey1##" ` What does the above line means ? Reference of PGMPATH is used as below : LIBS="${LIBS}:${PGMPATH}/edmz-par-api_1.4.jar" LIBS="${LIBS}:${PGMPATH}/commons-logging.jar" If it is telling the path where the jar file is located...

searching a specific word from a list of words in batch file

batch-file,cmd,scripting
I have a %list% variable which has words (see the code) and I want to search a word which ends with letter 'Y' (ignoring the case-sensitive) and which starts with the last letter of user's input. User input would be any valid word. Once I find that specific word then...

How to copy from list of files based on first character

shell,unix,scripting
I have requirement where I need to copy files from the list based on first character. Below if you see i have three line in list file and i need to copy line which start with M and A to new location for example (destination/testfolder) along with folder structure. Code...

Count specified words in file

linux,bash,scripting
I want to make script, that finds how many words, that I chose, are in my chosen file. Here is my script: #!/bin/bash echo "Iveskite reiksme kurios kurios kurios ieskosime faile" read reiksme echo "Nurodykite faila kuriame ieskosime reiksmes" read failas kiek=$(awk '/$reiksme/' $failas | wc -l) echo $kiek >...

Using a bash script to apply another script to every file in a directory like a matrix

bash,shell,matrix,scripting,file-handling
Let's say in my directory I have five files. Files: 1,2,3,4, & 5 I have a script that will do a mathematical process to compare two files and I want to use this script on every file in the directory, example below. compare file 1 to 2,3,4, & 5 compare...

BIOS level programming

scripting,boot,bios,low-level
I am trying to write a script that is executed before Windows is booted on my Computer. I have already developed a simple Linux bash script to accomplish this, but I would like to improve and take it further. The problem with using a Linux script is that it adds...

Passing argument function not working

bash,shell,scripting
valid() { if [[ "$1" = "0" ]]; then echo "Pass a file name as argument" exit 1 fi } valid if [ -f $1 ]; then echo "$1 exists" else echo "$1 doesnt exist" fi In the above example, the vaild() function is not working, why so? When a...

Trying to learn batch script, what does this do: /letter?

windows,batch-file,command-line,scripting,command-prompt
Here's the batch file: @echo off xcopy c:\testsource c:\testbackup /m /e /y So I know that "xcopy c:\testsource c:\testbackup" copies the files in the testsource directory and pastes them in the testbackup directory, but what does the "/m /e /y" do? Can you explain what each individual part of this...

Can I make _Assert write to console instead of a message box?

scripting,automated-tests,autoit
I am writing a script in AutoIt to test a windows application, and I am using the _Assert function to verify certain actions. In the documentation I found there is a parameter to say whether or not the script should end if an assertion fails, which is great because in...

Add “-I” flag to string of paths in bash

bash,shell,scripting
Having a string of space separated paths, relative or absolute, example: /aaaa/bbbb/ccc /ddas/sdsa/dasd ./dasd/dsd dasd/dsda/dsd dsd/dsad/erer/rerer ../dasd/dsad ../../sdasd/sdsd How can I process this in bash in order to prepend every one of these paths with -I? Example output should be: -I/aaaa/bbbb/ccc -I/ddas/sdsa/dasd -I./dasd/dsd dasd/dsda/dsd dsd/dsad/erer/rerer -I../dasd/dsad -I../../sdasd/sdsd Thanks Edit for...

If file is exists and is not empty. Always gives me the false value

linux,bash,scripting
I have a bash script: echo " enter file name " read $file if [ -f "$file" ] && [ -s "$file" ] then echo " file does not exist, or is empty " else echo " file exists and is not empty " fi No matter what I enter...

Adding up certain values in a Column for certain Rows USING AWK

linux,shell,awk,scripting
I want to sum up the values in Column 4 for the Rows whose Column 3 is equal to 1 using Awk for the data given below. 13.804 2 1 0.128 14.10683054308584 13.805 4 1 0.1 16.404063320609485 13.845 4 1 0.1 18.88784810910845 13.887 3 0 0.5 15.885403793537332 13.900 2 1...

Using excel as inputfile in vba (scripting - non MS OFFICE)

vba,scripting
I'm developing a script in VBA (inside a workspace, not MS office program) that needs to use a small excel file as input. I want to use the data in the excel file and load it into a 2D array so that I can make decisions within my script based...

bash script case statement needs to detect specific arguments

bash,unix,scripting,arguments,lines
I have to write this script where it will display each entry that is entered in on its own line and separate each line with "*****". I've already got that down for the most part but now I need it to detect when the word "TestError" and/or "now" is entered...

find command works on prompt, not in bash script - pass multiple arguments by variable

linux,bash,shell,scripting,quoting
I've searched around questions with similar issues but haven't found one that quite fits my situation. Below is a very brief script that demonstrates the problem I'm facing: #!/bin/bash includeString="-wholename './public_html/*' -o -wholename './config/*'" find . \( $includeString \) -type f -mtime -7 -print Basically, we need to search inside...

Looping variables

perl,scripting
I'm working with perl to make a script that will work with Dot products/assorted vector math. I've got a working script ( Still very much in progress/needs refinement ) that will do what I ask. #!/usr/bin/perl use strict; use warnings; use diagnostics; use Math::Vector::Real; use 5.010; use Math::Trig; my $source...

Reading rsync source from file results in improper parsing of file names with white space

bash,shell,unix,scripting,rsync
I wrote a simple script that searches through a specific directory defined by the variable "SCOPE" producing a list of directories that were modified within the past 24 hours printing them to a temp file. The first line of the file is deleted (to exclude the root level of the...

Is it possible to run command “route -n” specifically for a NIC

linux,shell,scripting
I am fairly new to linux I wanted to ask if its possible in linux commands to run a "route -n" command to retrieve information for a specific NIC. E.G route -n ether0. Because currently it shows me for all the NIC's but what if I want just for one?...

Insert variable value or default value if empty in a string

bash,scripting
I want to insert the value of an environment variable in a string or a default value if the corresponding variable is not initialized. Example: if [ -z $MY_VAR ]; then MY_VAR="default" fi echo "my variable contains $MY_VAR" I'm however using a lot of variables in my strings and the...

shell script to copy files from one directory to another

shell,scripting,terminal
Trying to write a simple script to copy some files in OS X 10.9. Here's the content.. SRC_DIR="~/Library/Preferences-Old" DST_DIR="~/Library/Preferences" FILEN="test.txt" cp $SRC_DIR/$FILEN $DST_DIR Gives me the output: cp: ~/Library/Preferences-Old/test.txt: No such file or directory Of course, the above is wrong. The exact same cp command in terminal directly does the...

interpreting a script through F#

scripting,f#,interpreted-language
I really like F# but I feel like it's not succint and short enough. I want to go further. I do have an idea of how I'd like to improve it but I have no experience in making compilers so I thought I'd make it a scripting language. Then I...

Bash script does not sort by file type after IF

linux,bash,scripting
I need some help, guys. I have a bash code #!/bin/bash echo "Iveskite kataloga, kurio analize norite atlikti" read katalogas failai=$(find -x $katalogas) for failas in $failai do if [[ -d "$failas" ]] then echo $failas " yra direktorija " else if [[ -x "$failas" ]] then echo $failas "...

Unix How to check if a specific word is entered in as an argument

bash,shell,unix,scripting
I'm writing a script in unix but I need a way to check an argument that is entered in the command line is a specific word. So if when using the script the user types: $ ./script hello my script can tell that "hello" was entered as an argument and...

Bash script error server issue

linux,bash,syntax,scripting
I have the following bash script #!/bin/bash servers="server1.... server2...." seconds="3" # value for servers to differ (in seconds) now=$(date +%s) for server in $servers do ssh -l root ${server} "( date +%s )" > /tmp/.tmpdate echo "-" $(date +%s) >> /tmp/.tmpdate difference=$(awk -F '-' '{if ($1-$2 < 0) { print...

Modify command line arguments in bash script itself [duplicate]

bash,command-line,scripting
This question already has an answer here: Modifying a parameter pass to a script (Bash) 3 answers Can i change command line arguments (like $1,$2) in bash script itself? I tried stuffs like this: $1='a' read var $1=$var ...

Bash Shell Scripting - Dialog form variables

bash,shell,variables,scripting
So, I just took up Shell Scripting and I'm developing an address book. For the user to insert a contact I made this form: form=$(dialog \ --title "INSERIR" \ --form "" \ 0 0 0 \ "Nome:" 1 1 "$nome" 1 10 20 0 \ "Morada:" 2 1 "$morada" 2...

bash getopts validate options

linux,bash,scripting,command-line-arguments,getopts
I have following code in bash script: # argument validation and usage help usage() { cat << EOF usage: $0 options File Integrity Monitoring Script: OPTIONS: -b input file for [backup] -r input file for [diff report] -l list backup files EOF } if [ $# -eq 0 ] then...

How to get the last parameter in shell [duplicate]

linux,bash,shell,scripting
This question already has an answer here: Getting the last argument passed to a shell script 21 answers I'm wondering how to obtain the last argument passed to a bash function, like this: #!/bin/bash function hello() { [email protected] # all arguments n=$# # number of arguments first_arg=$1 # argument...

Getting duplicate output

bash,scripting,sh
I'm trying to write a bash script that looks for a file in one directory and replaces it with one of the same name from a source directory. When I run the find command, it seems to be setting my $path twice for f in build-res/$1/*.png; do file="$(basename "$f")" echo...

Expect script for checking ssh connection for a list of ips

shell,ssh,scripting,expect
Can anyone help me in creating an expect script to just do an SSH on a list of servers and check if it was fine. I do not need to interact, do not need to fire any command on each server, I just want to do an ssh and come...

Choose from multiple return values

powershell,scripting
When I have a function, which uses several Write-Output commands and returns single number, how can I get number value in function caller code? As far as I got, line [int] $var = Get-MyNumber(...) gets me the error Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Int32"". Probably...

How to use multiple classes in multiple files in scripts?

groovy,scripting
I need to make a standalone Groovy script that does not require compilation and runs without Groovy installed. It works well, but it fails to recognize any other script than the main script. My folder structure is the following: libs\ groovy-all-2.4.3.jar ivy-2.4.0.jar src\ makeRelease.groovy ReleaseHelper.groovy I am launching the script...

run command in autohotkeys n number of time

windows,scripting,autohotkey
I would like to make my command runs specific number(n) of times in autohotkeys. Example: ::t:: send test return Now you type t and press tab it prints test. I would like to specify number (e.g. 5). So command will type testtesttesttest (test 5 times). Pseudo code something like this:...

Iterating over dates with a bash loop in bash — for (( … )) not working correctly

linux,bash,date,scripting
I am trying to create a list of dates. This script below works with simple dates with no spaces. datestart=20130601 dateend=20130705 for (( date1="$datestart"; date1 != dateend; )); do date1="$(date --date="$date1 + 1 days" +'%Y%m%d')"; echo $date1; done When I use a data string like (which contains WHITE SPACE) datestart="2013-06-01...

Local file existence condition in bash FTP script

bash,scripting,ftp,local
I want to get a file from a server conditional on the non-existence of the file in the local directory. In the final script there will be many files but here is an example just using one. I'm trying this: #!/bin/bash HOST='a.b.c.d' USER='anonymous' PASSWD='pass' ftp -n -v $HOST << EOT...

Calculate Date with PowerShell

powershell,scripting,system-administration
I am trying to create a script in Powershell that will; Get Last Bootup Time of the PC and check if it's greater than 48hrs If it's greater Reboot machine Else exit I can't seem to get it to calculate correctly. cls # Declaring Variables $lbt = Get-CimInstance -ClassName win32_operatingsystem...

Converting a Shell Script Into a *.app File

osx,shell,scripting,executable,desktop
Using Automator.app and Platypus.app, I have been able to bundle a simple shell script I created to power cycle wi-fi on my MacBook Pro. Both resulting apps run properly, but have one glaring issue that I want to correct: The apps reference the shell script from outside of the program....

Bash script not returning any output

linux,bash,shell,scripting,automation
I'm a newbie in the linux environment, and I'm starting to create an automated smoke test for several commands we frequently use at our company. Basically, running some kind of shell script that runs through multiple commands and also validates the command's output. The first test cases I started writing...

How to run windows executable and delete files from sub folders

vbscript,scripting
I need a quick script do two parts. Run a windows executable Delete files within a folder and subfolders (*.jpg, *.img). The first part of the below script works (running the executable) but I am getting stuck on part 2. I get Cannot use parentheses when calling a sub The...

Google sheets: Email each sheet to different email address listed in Cell G3

google-apps-script,scripting,google-spreadsheet
I am building a sheet that emails individuals PDF reports. I have this script working with a "hard coded" email address, however since each page of my google sheet needs to go to a different person. I am trying to figure out the language to make it look into the...

If a location exist with os.path.isdir by passing a user input variable

python-2.7,scripting,user-input,os.path
My python code snippet is some what like this CLName = raw_input ("\n\nEnter 7 digits CL number !") if os.path.isdir("\\\\abc\\\Compiler_Builds\\\something\\\CLName"): print "CL Exists" \\\\abc\\Compiler_Builds\\something is a local windows server location. In the above code I want os.path.dir() to check if the path \\\\abc\\\Compiler_Builds\\\something exists by inserting CLName at end, which...

Copy file from one folder to another and then rename using current date/time and new file ext using PowerShell or Python script

python,windows,shell,powershell,scripting
I do not have any experience with PowerShell scripts so I need some help to create a simple shell script. The shell script needs to do the following: The script will look for a file name with .upl file extension in the directory M:\ProgramData\Aspect Software\Unified IP\Advanced List Management\tenant1\xfer\CRM_Upload.upl. The shell...

Conditional formatting VBA scripting (not IN excel)

vba,scripting,conditional-formatting
I've been developing a script that runs through a Txtfile, retrieves certain references, stores these refs in a variable in the form of ('ref1','ref2','ref3',...) so that after retrieving these refs I can query our database to retrieve 10 columns from the database. I add this result to a excel file,...

Linux bash scripting: sorting a list to use

linux,bash,shell,sorting,scripting
I'm implementing a sort-function in my script, but I have trouble in doing so: what I want to achieve is the following: bash script --sort 44 55 1 23 44 output: Pinging to 192.168.1.1 succes Pinging to 192.168.1.23 failed Pinging to 192.168.1.44 failed Pinging to 192.168.1.55 failed The pinging and...

Compare multiple server times to localtime

bash,shell,date,time,scripting
I am looking to compare x amount of server times to a control local time(current time at the running of the script) to check if any of the servers are out of sync with the current time. If the servers are more than a few seconds behind then throw and...

Start-WebAppPool for Powershell 2.0

powershell,iis,web-applications,scripting
I'm experiencing a problem: I need a command to use on two different shells that gives me the chance to restart a web pool appliction, but only one of these shells is 4.0 (and has the command Start-WebAppPool) and the other one has Ps 4.0... What I'm supposed to do?...

Running a script of any language in Ruby

ruby-on-rails,ruby,bash,shell,scripting
I can execute shell command in Ruby using: def run(code) %x[ #{code} ] end I can also evaluate Ruby script in Ruby using: def run(code) eval(code) end Is there a way to blindly execute/evaluate code as a shell script, regardless of the language? I'm thinking of including #!/bin/bash or #!/usr/bin/env...

diff command label format

linux,bash,scripting,diff
is it possible to get header or label on two diff file using diff or sdiff command or any other tool. following just example, we have a script which comparing 100s of file so it is good to know which one we are comparing.. currently: # diff -y --suppress-common-lines /tmp/file1...

Bash Case statement: check whether string ends in number

bash,scripting,numbers,case,ends
I'm writing a script and I'm kinda stuck at the following part: Inside a case statement, I want to check whether or not the "--sn" command is followed by a number (1-254). I thought i'd just use --sn*, but apperently * doesn't work for numbers? case "$1" in --sn* )...

Add custom client-side script that executes when on page

javascript,html,scripting
Suppose there is an external site that lacks functionality (by external I mean hosted and maintained by someone else), ¿is there any way to add a custom script to it that executes when on the page?

Checking Blank User Input in Batch file (No Input) [duplicate]

windows,batch-file,cmd,scripting
This question already has an answer here: set /p empty answer crash 1 answer So, I am asking the user to make an selection. The point of this question is to catch if the user hit just entered without any input. My plan is to find out if the...

Script to get List of logged in users

linux,shell,scripting,terminal
I'm writing a Shell script to get a list of logged in users, i want to show a list like this one : The user AAA is on tty3 The user BBB is on pts/0 Here's what i've written so far : echo "The user " | who | awk...

How to update %time% variable in Batch Script

windows,batch-file,scripting,cmd,command-prompt
I have a batch script for backing up databases. I echo the %time% that script starts and then the %time% it ends to a log file. Even though the script takes 5 minutes to backup our databases the end time is identical to the start time. @echo off :: Credentials...

Populating a zenity list with results from mysql

bash,shell,awk,scripting,zenity
I'm doing a small project using BASH for a "Phone Book". It stores the data in a mysql database and uses a temporary file to work with the Selects. I'm using zenity visual interface, so I want to display the data stored in the database using the Zenity List Dialog....

Rearranging a csv file

bash,shell,csv,awk,scripting
I have a file with contents similar to the below Boy,Football Boy,Football Boy,Football Boy,Squash Boy,Tennis Boy,Football Girl,Tennis Girl,Squash Girl,Tennis Girl,Tennis Boy,Football How can I use 'awk' or similar to rearrange this to the below: Football Tennis Squash Boy 5 1 1 Girl 0 3 1 I'm not even sure if...

Bash - Copy some files with same extensions and different names to multiple folders called like the files

linux,bash,shell,scripting
I want to do a script for linux that copy several files with same extension but different names into another directory with the same folders as files i want to copy and with the same name as the files, and these files, one by one, within their folder. Example, i...

Is it possible to check whether a script of any version has been included?

javascript,jquery,scripting,include,greasemonkey
Earlier this day I wrote a small script for greasemonkey which fixes the sometimes buggy auto scroll in the StackOverflow Chat. I did // @require jquery......... however that lead to some problems since the chat is already using jQuery in a lower version which is not compatible with a newer...

Illustrator scripting > select all paths using JS

javascript,scripting,adobe-illustrator
i need to do some tasks using illustrator js scripting and I am a bit confusing on how to select the paths that are previously draw using the software itself, so basically when I run my script with a open document with some paths, the script will select all and...

Batch loop through a delimited by hash string, which contain spaces and commas

loops,batch-file,for-loop,command-line,scripting
I have a string made of many parts separated by # char. Some of the parts may contain spaces and commas. I tried FOR loop but this doesn't work. @echo off set string_to_separate=11AAA#222 BB,333 CC,444DDD#555ee,77ff f#88g gg for /f "tokens=* delims=#" %%i in (%string_to_separate%) do ( echo %%i ) I...

Count line lengths in file using powershell

powershell,scripting
If I have a long file with lots of lines of varying lengths, how can I count the occurrences of each line length? Example: this is a sample file with several lines of varying length Output: Length Occurences 1 1 2 2 4 3 5 1 6 2 7 2...

Running rsync as root: Operations Not Permitted

osx,bash,scripting,permissions,backup
World! I have a backup script that would run rsync for every user and will archive their /User/user folder onto our shared drive. Running into an interesting problem with rsync: when executing the script as "sudo" from the shell as the current user I'm unable to preserve the permissions of...

Syntax error: “fi” unexpected (expecting “then”) in bash script

bash,command-line,scripting,sh
I try to do the script: #!/bin/bash IP='192.168.1.1' fping -c1 -t300 $IP 2>/dev/null 1>/dev/null if [ "$?" = 0 ] then echo "Host found" else echo "Host not found" fi and i turn it: [email protected] ~ $ sh /home/pi/sh/test.sh /home/pi/sh/test.sh: 9: /home/pi/sh/test.sh: Syntax error: "fi" unexpected (expecting "then") where is...

mkdir $variable/$variable2 does not work

linux,bash,scripting
#!/bin/bash echo "Iveskite teksto faila is kurio norite paimti pirma eilute" read failas echo "Nurodykite kataloga kuriame noresite sukurti naujus katalogus" read direktorija mkdir -p $direktorija head -n1 "$failas" | while read pavadinimas do mkdir $direktorija/$pavadinimas done my $failas is: pirmas antras trecias ketvirtas penktas sestas eilutes i kurias mano...

How to provide Scripting support for Qt-Applications?

c++,qt,scripting
I'm looking for a scripting language which can be integrated into my Qt5 Application. The application has a public api, which can be used to extend the application with plugins. Now I want to add a scripting language to the application which provides access to the whole public api. The...

passing wildcard arguments from bash into python

python,bash,scripting,arguments
I'm trying to practice with python script by writing a simple script that would take a large series of files named A_B and write them to the location B\A. The way I was passing the arguments into the file was python script.py * and my program looks like from sys...

Python parsing using JSON for use with seleium

python,json,parsing,selenium,scripting
I'm trying to write a python script that will read in a JSON file with the aim to show how many screens are available and be able to pull the value of the different json fields JSON { "screen": [ { "id": "1", "user": "[email protected]", "password": "letmein", "code": "123456" },...

Parsing the text file line-by-line using batch script (batch file)

windows,batch-file,scripting,cmd
So, I am programming in the batch script and I came across this issue. The following code will take yourwords.txt file and parse it. The existedWord variable will have the last word of the text file. So, everytime when I run this program it will only compare the user's input...

What are valid input DATE formats for the (Linux) date command?

linux,bash,date,scripting
The following command generates the date for the next day: date -d "20150615 12:00 +1 day" +%Y%m%d 20150616 I would like to specify my own INPUT date format, such as: 2015_06_15 But the date command does not like this format and complains about invalid date: date: invalid date '2015_06_15 12:00...

Unix command error

shell,unix,scripting
when I try this command I'm getting the right path find /home/*/*/*/*.log result is /home/blross23/karthi/mmw/sample.log But When I try this command find /home/*/*/*/*.log -mtime +1 -type f -size +2 -printf "%s %h%f\n" The result I'm getting is 7950 /home/blross23/karthi/mmwsample.log where at the end of the path "/" (mmwsample.log )is missing...

Capture Output of dscl Command for Backup Script

osx,bash,shell,scripting,backup
I am currently managing a fleet of Macs that are being recycled so we need to figure out a way to automate a onetime backup of a user's folder (excluding any superfluous accounts like Shared or root) on the system to a network share using rsync. I would like to...

Coroutine loop freezes on unity3d run time

unity3d,scripting,coroutine
this is my unityScript code that have a simple coroutine loop. this Code works very well with editor test but on mobile phone and real time test the counter freezes if you want to go to main menu and come back again for counting down. in other words you start...

for loop run command in from file

linux,bash,for-loop,scripting
I have store commands in file and i want to capture their output, but what is wrong here? I want to capture output of each command and store in relevant file. Following just example, i have 100s of command which i want to run and capture optput but i just...

bash script echo arguments into separate lines

bash,unix,scripting,arguments,lines
I have to write this script to separate arguments entered in the command line. Here is the script so far: # template.sh function usage { echo "usage: $0 arguments ..." if [ $# -eq 1 ] then echo "ERROR: $1" fi } # Script starts after this line. case $1...

Why do we need to make file executable when using shebang?

shell,unix,scripting
I am a unix newbie and exploring the functionalities of shebang line. For example, let's say I have a program program.py to execute. One way to execute is to directly call the interpreter command: python program.py If using the shebang line, I will include: #!/usr/bin/env python at the beginning of...

bash functions returns “command not found”

bash,shell,scripting
I've been trying to get this function to work without returning errors, but so far I'm unable to figure out what the problems is. I'm using $(report_home_space) to insert the contents of the functions on a small bit of hmtl but keep getting the error: report_home_space: command not found on...

Python: Cycle Through the Alphabet

python,string,loops,scripting,alphabet
I'm creating a script that cycles through the alphabet, after that a new letter is added that cycles through again. Here's my code so far: import string for a in (string.ascii_letters + string.digits): print (a) for a in (string.ascii_letters + string.digits): for b in (string.ascii_letters + string.digits): print(a + b)...

Deleting upto a line

bash,perl,shell,sed,scripting
I have a line that looks like: foo cat dog = -48.34277635 foo(horse->0) = -60.34277635 and I only want the last set of numbers: -60.34277635 The line is formatted with that exact spacing. I've looked everywhere for a simpler solution, but I can't find anything without chopping the file piece...

Using sed to get the content of a file that is not between two lines

bash,shell,sed,scripting
I have a file like: name 1 name 2 name 3 #START# no name 1 no name 2 #END# name 4 And I'm looking for the opposite of sed -n '/#START#/,/#END#/p' to get as result: name 1 name 2 name 3 name 4 What's the secret?...

find the lines where sequence/sorting is broken in linux

linux,sorting,awk,scripting
I have a log file which contains lot of logs and first column contains the epoch time stamp, Ideally they should be in sequence/sorted. however if something goes wrong in system timestamp resets to some default value and sequence breaks and restarts. I am trying to find the lines where...

Error while executing lsof from bash script

linux,bash,shell,scripting
I am trying to check for the process which are running on a particular port and if present kill them, as i have to start another process on that port. Below is my code snippet. #!/usr/bin/env bash TEST_CASE_PATH="$HOME/Projects"; #kill Previous Process Running on port 9130 OUTPUT="$(ls -1)" echo "${OUTPUT}" #...

Batch find and replace chars in string

batch-file,search,replace,scripting
I have two string variables: @echo off set string_1=abc def ghj set string_2=abc_def_ghj In string_1 I need to replace spaces with %20, so the result will be: abc%20def%20ghj In string_2 I need to replace _ with spaces, so the result will be: abc def ghj I need to use batch...

Bash Script division

linux,bash,scripting,division,operand
I'm a beginner in scripting. I have a temperature sensor which gives me temperature if I cat the file /sys/bus/w1/devices/28-000006c5772c/w1_slave. The output of the file looks like: 83 01 4b 46 7f ff 0d 10 66 t=24187 As you can see the temperature is t=24187 which I have to divide...

Compute checksum on file from command line

linux,shell,scripting,checksum
Looking for a command or set of commands that are readily available on Linux distributions that would allow me to create a script to generate a checksum for a file. This checksum is generated by a build system I have no control over by summing every single byte in the...

Set key value pairs in a shell script

bash,shell,scripting,bash4
I have a shell script to bootstrap my machine: https://github.com/pathikrit/mac-setup-script/blob/master/setup.sh I have these few lines of code to setup git: git config --global rerere.enabled true git config --global branch.autosetuprebase always git config --global credential.helper osxkeychain I would like to extract that out to an associative array (a dictionary/hashmap) at the...

.bat script to Search all drives for existing subfolder

windows,batch-file,scripting
Currently I have this: for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do ( if exist "%%d\Program Files (x86)\Folder": ( cd "%%d\Program Files (x86)\Folder\subfolder\file" ) ) But it doesn't seem to...

How to write a shell script to compile and install ProFTPD by source compilation?

bash,scripting,proftpd
I installed ProFTPD by source compilation and has worked successfully, but I'm thinking, instead of separately doing the all steps, the entire installation can be done by using bash scripting, but I had less knowledge in shell scripting. Please help. These are the following commands I had executed to build...

Using Gawk and Printf in a Bash script

bash,scripting,printf,file-handling,gawk
I am trying to separate a file into smaller files with gawk and rename the smaller files in order from the original file. for i in *.txt do gawk -v RS="START_of_LINE_to_SEPARATE" 'NF{ print RS$0 > "new_file_"++n".txt"}' $i done The output gives me: new_file_1.txt new_file_2.txt ect... I would like the output...

Rename a bunch of PNG images with “.jpg” extension to “.png”

image,bash,scripting,png,jpeg
So I have a folder with thousands of image files, all of them saved as .jpg. The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png. For example, the Ubuntu...

How to make gnuplot to NOT plot multiple lines?

plot,scripting,gnuplot
I am plotting some data and I am getting multiple lines streaking across the plot. There should be one line, so I imagine that gnuplot is trying to fit the data and is joining points or something in a strange way. How can I get gnuplot to plot one like...

Expand ~ in Bash [duplicate]

bash,shell,scripting
This question already has an answer here: How to manually expand a special variable (ex: ~ tilde) in bash 8 answers I tend to visit the same directories during the course of a workday. Using the dirs -v command I can keep a list in a file dirs -v...

Execution Success, but no Results?

java,javascript,google-apps-script,scripting,google-apps
So, i'm working on creating this approval workflow for google forms. I'm new to this, I've searched online and read through some tutorials as well as google's but most of the stuff that I have seen has been deprecated. I think i have my triggers current, they're set to onformsubmit...

Can't capture the ouput of the paste bash command

bash,shell,scripting
( ping -n apple.com | ack -o --flush '((?<=icmp_seq=)[0-9]+|(?<=time=)[0-9]+[.][0-9]+)' | paste - - ) > ~/Desktop/ping_ouput.txt Doesn't seem to be working for some reason, whereas if I take away the | paste - - section, it works just fine. I need to join every other line together with a tab...

Detecting corrupt characters in UTF-8 encoded text file

regex,encoding,awk,utf-8,scripting
I have a text file that was edited with the wrong character encoding and thus has some mojibake and corrupt characters in some of the strings when I open it using UTF-8. What scripting language would be the most efficient at detecting these corrupt characters? Perl is not an option....

Based On Styling Indesign Javascript Scripting CC

javascript,scripting,indesign,jsx
I would like to know how I can set ( either directly or some other alternative method ) the style property of "Based on" using javascript within adobe InDesign CC. If I could also ask for documentation leading to an answer for reference it would be immensely appreciated. My code:...