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

learn more… | top users | synonyms (2)

0
votes
3answers
165 views

How to run a script in multiple instances ? ( Ubuntu server )

How can I run a script in multiple instances in Ubuntu server? For example, I have a long running script named scanner.sh placed in /usr/bin/, which I wish to run the script in 10 parallel ...
1
vote
2answers
71 views

A tiny and simple script fail and this is the output “No such file or directory”

The script is: #!/bin/bash IFS=" " command="ls /tmp" for file in `$command`; do echo $file done And the output is: $ ./test.sh ./test.sh: line 17: ls /tmp: No such file or directory
1
vote
1answer
66 views

ffmpeg script - slicing a video into multiple slices

I am currently using ffmpeg to slice video files. I automated the process through a script called ffmpeg_split.sh. To view the script click here. When I run the script I have an error when trying to ...
-2
votes
1answer
66 views

How to use `cal` to run scripts? [closed]

I wrote a script and need to make it run with the cal command. How do I do this? This is my .bashrc: PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:.
9
votes
4answers
289 views

Unexpected EOF and syntax error

I am currently writing my third ever shell script and I have run into a problem. This is my script so far: #!/bin/bash echo "choose one of the following options : \ 1) display all current users \ ...
2
votes
2answers
78 views

Add Text to Command Line via Shell Script

I have a shell script which is opening different terminals. After opening the terminals, I manually start different applications in the terminals. I would like to automate this by adding text (e.g. ...
3
votes
2answers
85 views

How can I run a script when internet connection is about to get lost?

I use wvdial (PPP dialer) with sim card modem and sometimes this connection is reset by server side. I would like to run a script which greps ifconfig to get a volume of data downloaded and stores it ...
4
votes
3answers
181 views

Script to compare 2 input paramters and show shared letter(s)

I am writing a script that I want a user to enter two separate words, and the result to show which letter the two words share. For instance ./share Cat Rat - would return shared letters: "a" and "t". ...
0
votes
2answers
63 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
4
votes
2answers
133 views

When is 'if' not necessary?

In some scripts, I've seen if conditional statements written as: if [ some_conditional_statement ]; then # do stuff fi or [ some_conditional_statement ] && #do stuff Is the second ...
2
votes
1answer
64 views

bash_logout only run command on last logout

This command is in my .bash_logout script to delete a temporary directory when I logout after running some processing: /bin/rm -rf /tmp/tmpdir/ However, I usually have more than one connection to a ...
0
votes
1answer
69 views

Command to list all usernames on a Linux server

What is the command that allows one to generate a list of all the usernames of authorised users on a Linux server? I have tried getent passwd | cut -d : -f 1 | xargs groups and less ...
3
votes
3answers
271 views

How to copy, execute and retrieve data from a remote computer?

I am trying to run some calculations on a remote computer. Basically I want to copy some files to the computer, load a software, execute the calculation, then retrieve the data back. I have created a ...
2
votes
2answers
150 views

How to get grep exit code but print all lines?

I'd like to check whether a line printed by a command contains an error message, but I'd like to also print all the output from the command (for make logs). Is there some way to get all the output of ...
2
votes
2answers
170 views

Shell script to merge files with same names

I have a directory of files such as: file.1111111_1.pdf file.1111111_2.pdf file.2222222_1.pdf file.2222222_2.pdf … file.1234567_1.pdf file.1234567_2.pdf … file.aaaaaaa_1.pdf file.aaaaaaa_2.pdf … ...
3
votes
1answer
238 views

Finding largest file recursively

I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file ...
0
votes
1answer
83 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
-2
votes
1answer
3k views

convert CSV to XLS file on linux [closed]

The following Perl script can convert CSV file to XLS file the problem is that I need to install on customer Linux machine many Perl modules in order to run this Perl script , and actually I cant ...
0
votes
1answer
129 views

Using Grep Colour to look in a file, and output with a coloured answer in amongst the file contents

I am currently in the process of writing a program in raspberry pi that will allow me to look inside files and have what I entered displayed in colour I think I need to do something to do with ...
5
votes
1answer
89 views

How to end a shell script?

I'm partway writing a script on Linux and I wanted to add an extra bit and ask the user whether they want to quit the program, can anyone help me in figuring out how I can do this?
0
votes
3answers
170 views

How does the following shell script work in finding all files larger than 20MB?

I came across a post advising that the following will find all files greater than 20Mb in size. find / -type f -size +20000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | ...
1
vote
1answer
57 views

Run Comand on all files (folders ad subfolders) [duplicate]

All, I have a lot of PDF files. Does there exist a way to apply to all PDFs in folder and sub-folders at one time? Example, I have: /pdf/test/pdfa.pdf /pdf/example/aa/test.pdf I'd like to apply ...
0
votes
1answer
91 views

SSH to a server, execute update command that continues even after logging off the ssh session

Okay I saw a lot of questions like this, but almost all have either theoretical answers which do clear the concept but I am still not able to put it up in code. What I want to achieve using a bash ...
0
votes
2answers
34 views

Using a file as an input to a script

Say I want to use the name of a file as input, and process it with a pre-made script in a certain directory. How do I do it? fileName < /folder1/scriptName is this the right format?
1
vote
3answers
108 views

Input two numbers and add them when “a” is typed, subtract when “s” is typed

So I'm having a little trouble with this code. When i try to execute I get the message line 12: 0: command not found #!/bin/bash let results=0; echo "First number please" read num1 echo ...
0
votes
2answers
50 views

check two partitions by selecting random files and running sha1 hashes on two files of each partition

A previous answer to a post mentions to run sha1 hashes on an images of a dd drive clone image. Another answer to that post suggests mounting the dd image an then compare if the sha1 hashes of ...
1
vote
2answers
97 views

run grep cmd recursively and print path name and result

I have a log file that exists in multiple directories one for each client. I am trying to run the following: find . -iname "20140926.log" -exec cat {} \; | grep 123456 | grep 'food="100"' | wc -l ...
0
votes
2answers
32 views

merge mutiple files using common column [duplicate]

Say I have multiple files x1, x2,x3,x4, all with common header date, time, year, age. How can I merge them to one singe file X in shell scripting? File x1: date time year age 101014 1344 2012 52 ...
2
votes
4answers
99 views

Bash - How do I loop through subdirectories and extract the files

I have a directory called 10K_TIF (main directory). Within this main directory are multiple sub-directories each containing tif images. I want to read each TIF image and extract its path using a bash ...
2
votes
2answers
89 views

redirect output of tee and grep for multiple logfiles

Redirecting output from a script STDOUT + STDERR toLogfile 1 and a grep to Logfile 2 ./run_test.sh 2>&1 | tee -a /var/log/log1.log | (grep 'START|END') > /var/log/myscripts.log How can I ...
2
votes
1answer
94 views

While loop checking JBoss status down or not, giving error

The intention of the following code is to check status of JBoss, the while loop iterates until the JBoss status comes to the 'DOWN' state. ` I have the following script, which I've set to this ...
4
votes
3answers
99 views

How to convert an unsigned decimal (less than 1<<32) to 4 bytes (binary) in bash?

Example: $ decimal=$(( RANDOM << 17 | RANDOM << 2 | RANDOM >> 13 )) $ echo $decimal $ printf "%08x" $decimal | xxd -r -p >bytes The result is in bytes file. Can it be done in ...
3
votes
2answers
41 views

How is it possible to execute a command with an unknown number of arguments in a POSIX shell?

I want to search for multiple words inside the current directory. To accomplish this I use something like this. grep -e "word1" -e "word2" -R . This works fine. Taking this one step further, I ...
1
vote
3answers
64 views

Modify some files to add the file name

I have a bunch of text (hundreds of txt) inside a directory. Each of them has a unique filename. I want to insert filename of each file into the first line of respective files. How can I do that using ...
3
votes
2answers
119 views

Extract text including parens

I have some text like this: Sentence #1 (n tokens): Blah Blah Blah [... ... ...] ( #start first set here ... (other possible parens and text here) ) #end first set here (...) (...) Sentence #2 ...
0
votes
3answers
91 views

Bash Combine Replacement and Sub String Extraction in One Step

For a string in this format: ./my-site.sub.domain.com I would like to remove the .,-, and /, and trim the remainder to 16 characters: mysitesubdomainc I've done this ...
2
votes
0answers
1k views

How to test shellshock against remote machine using a simple script [closed]

I am interested in testing for shellshock vulnerable machines that I don't have shell access to on my LAN's and WAN's such as IPMI cards and Internet of things devices. What is the best way to ...
3
votes
2answers
73 views

Parenthesis works in bash shell itself, but not in bash script

As the title says, I can run this command from my command line prompt: cp -r folder/!(exclude-me) ./ To recursively copy all contents of folder except for the subdirectory named exclude-me into the ...
0
votes
0answers
50 views

Ubuntu 14.04 HDMI UDev Script

I have tried multiple variations to this script but I cannot get it to work. The UDEV Rule fires the script and the script exectutes but simply does not change the audio profile. If I run the script ...
0
votes
1answer
44 views

How to move cron commands into a script?

Can someone give me an example that shows how to put Cron commands into a script? Using these commands as an example: find /home/network/public_1 -type f -ctime -1 -exec ls -ls {} \; find ...
1
vote
1answer
71 views

linux pgrep by excluding specific user

I'm using pgrep command on a shell script to monitor some java application. But there is a continues service from java which is giving problem on my code. That process belongs to another user. So, is ...
2
votes
1answer
1k views

Bash : syntax error near unexpected token ' done '

I wrote this script #!/bin/bash if [ $# -ne 2 ] ; then echo "\n Usage : sh $0 BSSID interface \n" exit 0; fi while true; do reaver -b $1 -i $2 -vv -N -g 10 -S -a sleep 3603; done ...
1
vote
0answers
18 views

Submitting a script to TORQUE `qsub`: PBS lines before or after shebang line?

I am submitting a script to a cluster that uses TORQUE. Should I add the #PBS lines before or after the shebang line?
16
votes
7answers
1k views

How to efficiently generate large, uniformly distributed, random integers in bash?

I have been wondering what would be the best way to get good randomness in bash, i.e., what would be a procedure to get a random positive integer between MIN and MAX such that The range can be ...
0
votes
2answers
73 views

7z from bash script won't exclude directories

I've encountered with kinda strange behaviour of 7z (or bash, I don't know yet.). With the following script: #!/bin/bash find /home/user -type f -name "*.pdf" | cut -c 10- > ...
2
votes
1answer
228 views

Shell command works locally but does not get parsed correctly through ssh

If I execute the following shell command locally, I get the expected result: adb -s 123456789 shell "su -c 'mount -o remount,rw /system;rm -r /system/app/MyApp.apk;cp /sdcard/MyApp.apk ...
3
votes
1answer
41 views

Why do I get an error when double quoting single quotes in a script that launches a remote SSH command?

I have this script: port=$1 cmd=$2 ssh root@127.0.0.1 -p $port "'"$cmd"'" When running myscript.sh 1000 "ls /dev/shm" it get this error: bash: ls /dev/shm: No such file or directory In the ...
1
vote
0answers
177 views

extracting data from a log file and plotting it using Gnuplot

I have a logfile with the following data in it: Sat Sep 20 11:25:01 BST 2014 -- temp=53.0'C -- message from script /usr/src/scripts/wifi_test_2.sh Sat Sep 20 11:26:01 BST 2014 -- temp=53.0'C -- ...
0
votes
2answers
352 views

scp with password and renaming the file [closed]

I need to execute scp command with renaming the file. I have tried with following code: HOST=lnx25 USERNAME=ngqa PASSWORD=xxxxx FILE=$1 FILE_NAME=`echo $FILE | awk 'BEGIN{FS="/"} {print $NF;}'` ...
1
vote
2answers
122 views

Extract text from one iteration of top

I want to execute the top command from my bash script the problem is that usually when I type the top command on the console , I exit by Ctrl+C. but how to exit from top when I run the top command ...