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

learn more… | top users | synonyms (2)

0
votes
1answer
20 views

Want to find a file Name starting with a pattern and ending with .csv

I have a folder in which I have many subfolders. The Root folder name is allCSV and sub foldername is will be like a_date(s), b_date(s), c_date(s) ... I want a file which is in a_date(s) and ends ...
105
votes
7answers
24k views

Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?

I notice that some scripts which I have acquired from others have the shebang #!/path/to/NAME while others (using the same tool, NAME) have the shebang #!/usr/bin/env NAME. Both seem to work ...
4
votes
3answers
114 views

Easiest way to find missing quote in a bash a script?

I have a bash script which is currently 700+ lines long. After a particularly long round of editing, it now errors like so: ./run_me.sh: line 693: unexpected EOF while looking for matching `'' ...
0
votes
1answer
18 views

cant run dd command on android device

The main objective is to send a splited file to an android and join it back up with a .sh script, the file is splited to 5MB parts but its total size is unknown (trying to make an universal script), ...
4
votes
4answers
122 views

Move files by date into different directory using CLI

I have a large number of pictures from an old hard drive that I'm trying to organize. If I run ls -l, I notice all of these files have a creation date of 2012 or before. Ideally, I'd like to move ...
2
votes
4answers
73 views

Extract two values from the output of a command

I'm using the following command in a script to get synthetic wifi info: echo "$( iw dev wlp1s0 link | grep '^\s*SSID:\s' | sed -r 's/^\s*SSID:\s//' ) $( iw dev wlp1s0 link | grep ...
2
votes
0answers
47 views

Checking if a specific key is pressed in shell script

Is there a way I can check if a specific key is pressed in a shell script which is running in background. Consider I am running a shell script which has to play a play list of songs as soon as I press ...
2
votes
3answers
44 views

How can I prepend and append to each member of an array?

I have an array: CATEGORIES=(one two three four) I can prepend to each array member using parameter expansion: echo ${CATEGORIES[@]/#/foo } I can append to each array member the same way: echo ...
16
votes
5answers
803 views

How can I propagate my SSH pub key to a list of servers without having to type my password in over and over?

I was recently given username/password access to a list of servers and want to propagate my SSH public key to these servers, so that I can login more easily. So that it's clear: There is not any ...
1
vote
1answer
61 views

Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?

Which one works faster - regular operators (such as <,>,=) or using (-lt, -gt, -eq)? and why?
3
votes
4answers
38 views

How to get the PID of a sub process across to the parent process in a bash shell script?

My shell script is as following: #!/bin/bash ./process1 #It will create a sub process: sub_process1 while [ condition ]; do break done kill -9 process1 and sub_process1 In my script, it will ...
1
vote
1answer
16 views

Script samba password but securely

I want to script the addition on a samba user and the password. I have seen solutions similar to the one here Piping password to smbpasswd echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN but ...
0
votes
1answer
34 views

Test variable in a bash case statement

What I want is simply to do something if the first variable of the script is empty, in a case statement. Unfortunately I spent yet a certain amount of time searching for the solution but didn't find ...
0
votes
2answers
24 views

Timeout function return value

I'm using the timeout function on debian to wait 5 seconds for my script. Works great but the problem I have is that I need a return value. Like 1 for timeout and 0 for no timeout How am I going to ...
3
votes
0answers
37 views

Bash Script — ffmpeg not being invoked as expected

I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it: ffmpeg -i "${file}" -f flac pipe:1 ...
0
votes
0answers
16 views
0
votes
3answers
110 views

How to loop through lines in a file which contains * in each line

I have a file that contains about 800 lines. All the lines contains 1 * character in it. I need to loop through the lines in the file so I used the following simple for loop for i in $(cat ...
0
votes
1answer
19 views

PHP script to monitor process and write status to a file

I want to write a php script for monitoring particular process using top command and write into the file. I use top -p pid for monitoring a particular process and also i write a shell script for ...
0
votes
2answers
337 views

Using chown $USER:$USER inside bash script

In a small bash script I'm running I am attempting to chown a new directory that is created. I've added: sudo chown $USER:$USER /var/www/$sitename sudo chmod 775 /var/www/$sitename after the line ...
3
votes
3answers
237 views

USB device to be detected at the “same” /dev point always?

In Linux (actually I'm with CentOS v6.5), whenever I plug in my USB Terminal/Character Device (some kind of USB Adapter) for the first time (after booted), it is detected at: /dev/ttyUSB0 But ...
1
vote
2answers
28 views

Url Decoding shell script

How can I store the url-decoded string in a variable using shell script #!/bin/sh alias urldecode='python -c "import sys, urllib as ul;print ul.unquote_plus(sys.argv[1])"' ...
4
votes
2answers
3k views

Copy ssh public key to multiple Linux hosts

I am trying to copy .ssh/id_rsa.pub from our central server to multiple servers. I have the following script which I usually use to push changes to the different servers. #!/bin/bash for ip in ...
1
vote
3answers
86 views

How to decode base64 text in xml file in Linux?

I'm new in linux (shell). I need to decode base64 text in xml file using linux shell script. Could you please help me to write linux shell script for decoding the values of those tags where attribute ...
0
votes
1answer
19 views

Help killing off Process for Mem Leak

I am currently building an Android LP kernel, and have some pretty sweet tweaks already running and built into it. I know there are numerous LP memory leaks (i've already got the bootanimation one ...
13
votes
5answers
19k views

Passing named arguments to shell scripts

Is there any easy way to pass (receive) named parameters to a shell script? For example, my_script -p_out '/some/path' -arg_1 '5' And inside my_script.sh receive them as: # I believe this ...
-1
votes
1answer
31 views

Webpage content - search for pattern & save to file

I have a web page, say https://test.salesforce.com. I would like to search for a pattern, e.g. "src" at the beginning of a line in the entire webpage content. If the pattern is found, I need to ...
2
votes
1answer
42 views

How do I properly escape this long su + sed command?

#!/bin/bash wineuser=tom su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh" The acutal line inserted to tom's ...
2
votes
1answer
99 views

How can I check if rsync made any changes in bash?

I have a script which uses rsync to sync data in a remote -> local scenario. Immediately after the rsync command is run, a check to see if the error code equals zero or not. If its zero, further ...
1
vote
1answer
47 views

Getting an output error with command head in shell script

getting an error with head command. There are two files with size 48bytes in directory and its printing once along with the directory path instead of twice. Why the head command is not considering the ...
-2
votes
1answer
112 views

How to find files with the smallest size in a directory

I need to find all files of the smallest size in a directory. My code so far: #!/bin/bash dir="$1" printf "minimum file size: %s\n" du $dir -hab | sort -n -r |tail This code ...
1
vote
2answers
111 views

How to find maximum and minimum file size along with their path in a directory

I want to find out the maximum, minimum and average file size along with their path. Incase a directory holds similar file sile (say 15kb,15kb) it should display the path of both files and its files ...
14
votes
3answers
327 views

Prepare answers for questions of a command

Let's say I want to write a shell script that executes just one command. But this command is poorly designed. It doesn't offer any command line options; instead it asks some questions and waits for ...
0
votes
0answers
23 views

Run Loop between starttime and endtime and get data from url

I want to check two conduction and run a loop for every one minute. There should be three variable start_time, end_time and current_time Conduction's: start_time should be greater than ...
6
votes
2answers
3k views

awk: forcing a return status?

This is a followup to my earlier question. I am validating the number of fields in /etc/passwd using this handy snippit. In the following example, the users 'fieldcount1' and 'fieldcount2' have the ...
3
votes
1answer
591 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
0
votes
1answer
37 views

need to get the command information over ssh and the input from file

I am writing a script to get the command information of the remote machine usinf while and for loop. PFB the script. But the script ends by giving the single command information only. I have multiple ...
0
votes
1answer
27 views

Delete excel files which are older then 1 month

I need to delete excel files which are older then 1 month. need to set cronjob. any suggestion for this? which script can be used to search excel files from particular directory and delete them.
3
votes
4answers
154 views

how to check directory is empty

I have a requirement, if I execute a script ./123 with an arguments of empty path, say /usr/share/linux-headers-3.16.0-34-generic/.tmp_versions(this directory is empty). It should display "directory ...
1
vote
0answers
37 views

Shell Script to change user shell

I am writing a script that would be invoked to change user shell. The basic requirement is that once user gets authenticated (e.g: thorough some web application) the script would be invoked to set the ...
8
votes
1answer
15k views

sudo: unable to execute ./script.sh: no such file or directory

I'm stumped. I have a script in my /home directory which is executable: [user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh However, when I attempt to run it with sudo it ...
1
vote
3answers
139 views

Find records present in file 1 also in both file 2 and file 3

I have three files file1.txt, file2.txt, file3.txt and they are of same format. I want to select records from file1.txt which are present in both file2.txt and file3.txt based on column 2 and column ...
5
votes
5answers
313 views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And if the circumstances are perfect, ...
2
votes
3answers
66 views

Help with String manipulation in shell

I was writing a shell script to generate a string in a particular format so that it can be used as a input in one of the XML I am working with. Given a input file in the format <attribute ...
0
votes
2answers
106 views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
0
votes
1answer
37 views

Parsing string on multiple parts without separator

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*" I would like to parse the string above. In my case, a string consists of 4 columns (every command has : separator) but it can be much ...
5
votes
5answers
7k views

Concatenate multiple files with same header

I have multiple files with the same header and different vectors below that. I need to concatenate all of them but I want only the header of first file to be concatenated and I don't want other ...
1
vote
0answers
26 views

Inherit IO redirections from a script to another

When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it. A: ./B 2>> error.log B: ...
4
votes
4answers
209 views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
3
votes
2answers
69 views

shell scripting remote commands through ssh

I'm trying to create a shell script which will execute some commands which I require frequently. I made the ssh login to skip the password prompt using a public/private key pair. and after some ...
0
votes
0answers
44 views

Shell script to send alert if mount point exceeds 75% [duplicate]

How to write shell script to send an alert if any file-system on server exceeds 75%, in one email notification instead of receiving separate alert email notification for each file-system. I am ...