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

learn more… | top users | synonyms (2)

5
votes
4answers
209 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 ...
0
votes
3answers
88 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 ...
1
vote
1answer
63 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
2answers
42 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 ...
-1
votes
1answer
42 views

Shell scripting enthusiast [closed]

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
34 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 ...
-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
70 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
66 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
164 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 ...
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
3answers
223 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() { ...
2
votes
4answers
147 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 ...
0
votes
1answer
51 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: ...
3
votes
2answers
84 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
3answers
90 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
5answers
137 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 ...
2
votes
2answers
55 views

Why does the while cycle skips and only reads the first line?

$ ls testscript.sh testservers.txt $ cat testservers.txt serverA IMM 10.2.3.4 USERID PASSW0RD serverB IMM 10.2.3.5 USERID PASSW0RD $ $ $ cat testscript.sh #!/bin/bash # test them.. egrep ...
0
votes
3answers
30 views

Shell script to produce duplicate output with increments

I need a script that will produce the following output many times @float Figure,fig:n @cindex @image{n,9cm}. @caption{} @end float but where n (both times) is replaced by 1, 2, 3, up to a large ...
1
vote
2answers
26 views

Bulk rename and resize with Imagemagick

I need to convert a very large number of images that are called 1a.jpg, 2a.jpg, 3a.jpg using Imagemagick to be processed and renamed 1.jpg, 2.jpg, 3.jpg (in the same directory). The Imagemagick ...
4
votes
4answers
270 views

A command that generates both standard error and output

I want to do some troubleshooting on my bash script. Is there a short and simple command that generates both stdout and stderr so that I can use 2>&1 on it? Sorry if this looks trivial, but I ...
1
vote
0answers
41 views

When gnu parallel exit,my program also fail

I use gnu parallel to run a bash function. The function just contains the bash script to restart my program. At first, the restart is ok, but when the gnu parallel script exits, my program also fails. ...
3
votes
2answers
50 views

Why is my trap not printing any log message?

What I'm doing is, trap 'rm -f /path/of/file/fileName.running; echo "TRAPPED & READY";' 1 2 9 15 >> trap.log I didn't get anything in log & the file which should have been deleted ...
4
votes
3answers
268 views

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command ...
0
votes
0answers
23 views

authenticate url with asked credentials

there is a URL http://server, when I open this url it ask for username and password (.htaccess authentication), this URL works fine in browser. This is the webpage not the browser which ask ...
0
votes
1answer
39 views

How to start a cron task?

It sounds really simple, but many times I was stuck at the beginning of learning a new command. The tutorial writer think it's natural to start, but it's not. This is the tutorial I've been reading: ...
4
votes
3answers
340 views

pipe line with non-deterministic output

I have happened upon a command that sometimes works and sometimes does not, even when executed multiple times in rapid succession in a bash shell (I have not tested the behavior in other shells). The ...
5
votes
2answers
77 views

Extract tomcat parameters from ps output

I'm trying to write a little diagnostic tool and one of the functions I want from it is that I want to run is: ps axu | grep tomcat | grep -v grep | awk '{ print $<list of desired fields> }' ...
1
vote
1answer
30 views

How to assign words with spaces as a whole name to variable in shell script? [duplicate]

I need to make some directory of Author name. It's easy when doing them alone. I can simply mkdir "Mario Luis Garcia" This will create one directory named "Mario Luis Garcia" But when trying do it ...
2
votes
1answer
467 views

Why is 'kill -9' killing browser as well as server?

I sometimes have to use kill -9 as a last resort to kill my rails server. Unfortunately, I have to do that often enough that I wrote a helper function in my bash_profile to do it. If I do it manually ...
-3
votes
1answer
39 views

How to interleave two files?

How do I take two input files and create an output file that interleaves their contents? For example, if one file contains: 3 4 6 9 1 7 3 4 5 6 3 5 7 9 10 And another contains: a d g e t u v g j j ...
2
votes
2answers
101 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 ...
0
votes
0answers
37 views

Updating data sets from Online databases/Webservice

I want to have an idea as to how to update the data regularly from the source, if its stored locally in your server or local machine.Lets say MySQL database. Source:It will be a webservice data ...
1
vote
1answer
45 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
3
votes
1answer
33 views

start-stop-daemon returning always 0 (success)

I have set up start-stop-daemon to start my script automatically case "$1" in start) log_begin_msg "starting foo" start-stop-daemon --start --chuid nobody --user nobody --pidfile \ ...
0
votes
0answers
49 views

Connect Unix and Windows using shell script

SRCDIR="source/directory" TMPDIR="temp/directory" [ ! -d "$TMPDIR" ] && mkdir -p "$TMPDIR" for file in `find "$SRCDIR" -ctime -1 -type f -name "abc*pdf*"`; do cp $file $TMPDIR done cd ...
0
votes
1answer
45 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 ...
0
votes
2answers
54 views

Shell script to work on files in some directory

I am a noob in Linux hence this might come as a silly question. I have a Windows system, so I downloaded cygwin to help me execute Linux/unix commands. I need to execute a shell script on a bunch of ...
0
votes
2answers
44 views

Getting expr: syntax error on index [duplicate]

Using this OF=$(ps fax | grep 'php-fpm: master process' | awk '{print $1}') IDX=`expr index $OF ' '` I get an error. The results of the $OF variable are: 27797 27495 What is the error here? I ...
0
votes
1answer
31 views

Echoing Total Page Number in Bash Script

I have the following script for batch pdf-ocr processing & it works fine #!/bin/sh # apt-get install exactimage tesseract-ocr ghostscript # bash tut: ...
1
vote
2answers
57 views

Shell script: whole directory to the remote ftp server

I am trying to ftp some recording files to a remote server for backup every night. I am very confused regarding shell script. My question / problem is : I want to move the whole folder/directory ...
0
votes
1answer
70 views

Reject SSH connections from unlisted countries, using hosts.allow/hosts.deny on CentOS

I was trying for few hours to make my custom script work when using hosts.allow/hosts.deny, to prevent connections to SSH and other services supporting TCP wrappers from unlisted countries. Example ...
-3
votes
2answers
54 views

Extract certain column from CSV files [closed]

I have a directory with a group of CSV files. All files have the same column headers. I need to extract values in a certain column from all files. The common part in files names is ...
1
vote
3answers
77 views

How to get a response from any URL?

I have been asked to write a shell script To check if a URL is UP/Working or not for my Project. I tried to find some hints over the internet, but whatever I got is about checking whether the URL ...
2
votes
5answers
42 views

Append files with bash one-liner?

Currently I use multiple lines to append content into a combined file, e.g. ./myprogram 1.txt > Out.txt # Overwrite for the 1st file ./myprogram 2.txt >> Out.txt ./myprogram 3.txt >> ...
0
votes
0answers
16 views

I have to calculate values from two files and store the result in output file [duplicate]

I have to calculate values from two files and store the result in output file: in output file each record shows the product of records with same name in input files. file one s1 10 s2 20, s3 25, s4 ...
-3
votes
1answer
81 views

I have to calculate values from two files and store the result in another file — using shell

I have to calculate values from two files and store the result in output file. In the output file, each record shows the product of records with the same name in input files. file one s1 10 s2 20 ...
1
vote
2answers
42 views

Sending most recently created file via Email

I'm trying to send a log file every 24 hours or so via email. Currently I am using mutt for this. You can call mutt like this: mutt -s "Log" -a file_attachment example@example.com I know I can ...
0
votes
1answer
56 views

Copy a file from a remote server to windows home using scp

Is there a way to copy a file from a server to a local folder (i.e. My Documents)? can it be done by scp? I have this script that generate some list. I want this script to automatically copy the ...
2
votes
1answer
45 views

Exit status on core dump

When a process dumps core, does it set any particular exit code? Alternatively, is there a way to detect if core was dumped in a shell script. I have shell script that fires a job which occasionally ...