Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

2
votes
2answers
79 views

How to check whether a particular port is open on a machine from a shell script and perform action based on that?

I am running my below shell script on a machine on which c++ application server is running on port 8080 and in the shell script I am executing an URL and stores the response coming from that URL in ...
1
vote
1answer
67 views

Command-line parameters in bash script not recognised

I use Debian (Raspbian) Wheezy. If this command line works fine: smsd -c sms/out -i 60 -0 -f sms/smsd.log and this alias also works fine: bsmsd='smsd -c sms/out -i 60 -0 -f sms/smsd.log' then ...
5
votes
1answer
595 views

Noninteractive script running over ssh is interrupted as apt-get finishes

When I run the following non interactive script on Ubuntu Server 13.04 it's interrupted when lxc-docker package finishes installation. Script : ssh -o StrictHostKeychecking=no -t -t -i $CERT ...
-2
votes
0answers
41 views

Unix date difference

I am getting error for this script can any one help for this one #!/bin/bash echo enter first time stamp read d1_1 d1_2 echo enter second time stamp read d2_1 d2_2 secdiff=$(( $(date -d "$d2_1 $d2_2" ...
3
votes
1answer
127 views

How do I fill my password automatically from .bash_profile when running command as sudo?

I know I could just put something like sudo mypassword in my .bash_profile, but I don't want to run every command as root. I want password to autofill under following circumstances: only the ...
3
votes
2answers
26 views

Problem with read variable from AWK

I'm trying to get memory info by this command: #!/bin/bash set -x cat /proc/meminfo | grep "MemFree" | tail -n 1 | awk '{ print $2 $4 }' | read numA numB echo $numA I'm getting this + awk '{ print ...
3
votes
1answer
26 views

Error when calling a script from inside another script

I'm writing a couple of scripts to start vlc and periodically update its playlist. The update_pls.sh works well if I execute it from prompt, but when I call it from start_vlc.sh, in each for cycle I ...
4
votes
3answers
98 views

Running commands on multiple servers [duplicate]

I want to execute a process on multiple servers. I am using the following wrapper script. The script moves to servers one at a time. I would like to change it so it can execute on multiple servers. ...
8
votes
1answer
13k views

How to check if there are no parameters provided to a command?

How do you check if $* is empty? In other words, how to check if there were no arguments provided to a command?
2
votes
0answers
51 views

How to write a shell script to run multiple command in different screen sessions?

My goal is to write a zsh script in order to create multiple screen sessions and run separate commands on each of them. I would also like to check at the beginning of my script if there are any ...
5
votes
2answers
447 views

How to append multiple lines to a file without last newline?

I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash. Example: First append cat >> abc.sh << EOL echo "bla ...
1
vote
2answers
54 views

I get a “command not found” error, though the script file is shown by “ls”

I want to run yii console commands in shell. I run protected/yiic in the console, yet it fails, yielding -bash: yiic: command not found What's the problem? See the shell commands and responses I ...
2
votes
2answers
247 views

condition && command + exit

While writing a simple shell tool, I found a piece where I don't know how to get it to work. [ "$#" -ne 3 ] || echo "wrong number of arguments" && exit The above works as intended because ...
1
vote
1answer
459 views

Script that unpacks a initrd, allows editing of the preseed.cfg and the packs it to cpio and gzip again

I want to program a script that allows what is said in the title. So basically I gunzip the initrd, than unpack the cpio, open vi to allow editing, save, pack with cpio, and gzip again, so nothing ...
0
votes
1answer
40 views

Centos - executing a bash script from PHP

I have 3 scripts (I have removed the help_page function from the networkstats.sh script when I pasted here to save some space): api3.php <?php output = shell_exec('/bin/bash ...
5
votes
4answers
423 views

How can I “lazily” read output from xrandr?

I have a bash script that I use to adjust my monitor brightness that uses xrandr --verbose to get the current brightness. It works fine, but using xrandr is kind of slow on my machine, as you can see ...
0
votes
0answers
14 views

AWS EMR Bootstrap

I need to write a bootstrap action file for my AWS EMR that runs during provisioning and performs: Install latest R version from: http://cran.us.r-project.org Install ‘lme4’ package (and all of its ...
0
votes
2answers
57 views

How to kill a process running in specific script

I have two script files running simultaneously. I just need to kill the java process running in one script without affecting the java process in the another one.
0
votes
1answer
48 views

Problems copying files with spaces inside the file name in a bash script [duplicate]

I have the following function inside a BASH script (running under Ubuntu 12.x), which would copy over a file with spaces inside the file name. It's not working. I've tried many different combinations, ...
0
votes
2answers
38 views

init.d script is not starting under virtualbox

The script is in /etc/init.d: #!/bin/bash VMUSER=myname CURRDATE=(`date +"%m-%d-%Y"` + `date +"%H:%M:%S"`) CURRTIME=(`date +"%X"`) FILE=/home/myname/log/vm-services.log VBPATH=/usr/bin start(){ ...
2
votes
1answer
600 views

How to strip color codes out of stdout and pipe to file and stdout

I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my ...
2
votes
3answers
1k views

How is it possible to sort ps command's CPU field?

I'm trying to make a small command that will find the processes that use the most CPU power. Firstly, I use ps aux > file.txt and then cut -c 16-20 file.txt | sort -n | tail -5. The result I get ...
2
votes
2answers
116 views

to compare two fields in two different files

In file1, I have 1023M BLD 123G DEV 945K Deployment 4899 INT In file2, I have 1.2G BLD 123G DEV 345M Deployment 499M INT I wanted to compare the first field of file1 with first ...
0
votes
0answers
11 views

Mutt multi content type

Good afternoon I want to send multiple content_type with mutt. Can I do that? Here is my code : mutt -e "set content_type=text/html" -e "set content_type=text/plain" someone@mail.com -s "Multi ...
1
vote
1answer
57 views

Why doesn't this piped script work?

#!/bin/bash rm out mkfifo out nc -l 8080 < out | while read line do echo hello > out echo $line done If I browse to the IP of the machine this script is running on (using port ...
1
vote
1answer
32 views

How could i flip content of a binary file with bash commands

I was wondering if it's possible to do bitwise conversion on a binary file, with bash commands, (in my case bitwise negation).
2
votes
1answer
34 views

Killing multiple instances of the script from the script itself

I've couple instances of script.sh running in parallel, doing the same thing, running in background. I'm trying to use a function to kill all the current running scripts when executed. So, for ...
0
votes
3answers
84 views

How can I get the pid of a process started this way

#!/bin/bash mkfifo /var/run/out while true do cat /var/run/out | nc -l 8080 > >( while read line do do some stuff done ) done How can I get the pid ...
5
votes
4answers
206 views

How to replace all the first occurences in matched lines with incremental number?

I have a file like this ... 1562 first part 1563 H col3 H col4 1564 H col3 H col4 ... 3241 H col3 H col4 3242 third part ... I want to replace only the first H in every line to H#, with ...
1
vote
1answer
49 views

How can I kill child processes with start-stop-daemon?

I'm writing a simple web server using nc and bash. It looks like this: #!/bin/bash rm -f /var/run/streamman/out mkfifo /var/run/streamman/out trap "rm -f /var/run/streamman/out" EXIT while true do ...
0
votes
1answer
31 views

How do I validate a settings(ini) file for the values expected using bash?

After I check if the ini file exists where it is expected to be, which I've learned how to do, I would like to check the file for proper formatting. I'd like to validate any number of "site" entries ...
0
votes
3answers
1k views

How do you create and execute a bash script which calls an executable from higher folder?

I'm attempting to write a very simple script which calls an executable from a higher level folder. If I were just typing the command into the console, I would type ../filenamehere {options} ...
-1
votes
1answer
40 views

Shell scripting enthusiast [on hold]

This may sound generic and non technical to many but i can use some quality advice here. I am an technical support engineer who happens to be interested in shell scripting. My job does not need me to ...
0
votes
2answers
25 views

Editing /etc/init.d/mysql to remove mysql.sock automatically

I am running MySQL on a CentOS release 6.5 (Final) virtual machine. It is used for testing Joomla. The phyiscal host reboots frequently, which is fine. The VM, however, does not perform a clean ...
3
votes
3answers
214 views

Preventing a specific space from being expanded in a variable

In bash how do you avoid a specific space from being expanded in a variable? Lets say I have this JAVA_OPTS="-Xmx1g" JAVA_OPTS="$JAVA_OPTS -XX:OnError='/path/to/a/script.sh %p'" function args() { ...
3
votes
2answers
83 views

exit a script if an ls line did not find any match

I am writing this script that have this line: ls -lrt /dir1/dir2/filename*.txt | tail -1 | awk '{print $9}' | read variable What I wanted is to exit the script (without using if-statement) if it ...
3
votes
1answer
24 views

X commands do not start from my at job

I'm learning about Linux scheduling commands including at, cron, sleep etc. I'm trying to launch gedit after x minutes via the at command. This is what I have: kedar@i5 ~ $ at now + 1 minute at now + ...
3
votes
2answers
4k views

How can I trim the carriage return from text that is being piped in bash?

I'm using this command to get my last typed command: history | cut -c 8- | tail -n 2 | head -n 1 It works very well in bash, removing the line numbers, but there is one problem I have with it, (er, ...
-2
votes
2answers
35 views

Identifier must be declared [closed]

Hi I am new to Shell scripting , and I am facing this issue for days, can someone help me out? my snippet : filename='somefile_Connectivity_12345.CSV' trimfilename= echo $filename| cut -d'_' -f ...
2
votes
2answers
68 views

How parse a log file for a string, and when found search backwards for another string

I use the following command to parse a log file for a particular string. Then I search backwards in the log to find the data I really want. The problem as in the example below, I am only going back ...
4
votes
2answers
63 views

Using $ in a password

Lets assume that password of my server is Abcd$1234 I am trying to ftp a file from other server to my server using the following in shell script ftp -inv (IP) << EOF user Username Abcd$1234 ...
3
votes
1answer
162 views

How does the colon sign and dollar question mark combine in sh?

The "colon sign" and the "dollar question mark" can be combined to check if a sh script does have an argument and assigns it directly to a variable of interest: cmd=${1:? "Usage: $0 ...
10
votes
4answers
5k views

How to define and load your own shell function in zsh

I am having a hard time defining and running my own shell functions in zsh. I followed the instructions on the official documentation and tried with easy example first, but I failed to get it work. ...
0
votes
1answer
69 views

Parse lines of output from bash loop

I'm trying to parse the output of commands run in a bash loop. Here is an example: $ for i in `git log --format='%H'`; do echo $i ; git branch --contains $i; done | head -n 8 ...
2
votes
4answers
146 views

Execute all files in a list

I have a source tree which, when make is run, produces several executables named "001", "002", and etc. I'm trying to write a script which will find all of these executables in my source tree, and ...
3
votes
3answers
74 views

Script to email all matching files in a directory

Trying to set up a bash script to automate sending data files. Desired end result is to check a specified directory once per week, make a list of all Excel files modified within the last 2 days, and ...
0
votes
1answer
45 views

Using bash's “source” command return error though it successfully read config file [duplicate]

I want my bash script to read parameters from config file. Here is what inside the script: #!/bin/bash source /home/myscript/conf/config.conf echo "$username" and below is my config.conf: ...
7
votes
4answers
26k views

Splitting string by the first occurrence of a delimiter

I have a string in the next format id;some text here with possible ; inside and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; ...
1
vote
1answer
48 views

Toggle Skype notification status

Being notified whether a contact appears online/offline or not can be changed via the Skype Options or via the ~/.skype/your_skype_id/config.xml. In this file, depending on what you chose, on can find ...
0
votes
5answers
127 views

Move files to multiple folders [closed]

I've searched for this function, and there are lots of answers, but I haven't been able to find anything that works for me. I have a folder with about 30,000 files, and I want a terminal command or ...