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

learn more… | top users | synonyms (2)

-2
votes
0answers
9 views

Copying a number to a variable from a text file

Suppose I have a text file: abc.txt which contains 1 2 3 4 I would like to store the value 3 from the txt file in a variable (say x). Please suggest.
-2
votes
0answers
7 views

Ask for a desired prompt and change to that prompt and display welcome messege to logged in user [on hold]

A shell script that will ask for a desired prompt and change the prompt accordingly. Also it will display a welcome message to the currently logged in user by his or her name.
-2
votes
0answers
8 views

Accept a user name and display all information of his/her from file /etc/password [on hold]

A shell script that will accept a user name from user and display all information of him/her from file /etc/password.
-2
votes
0answers
6 views

Find PID of current shell and no. of positional parameters and PID of last bakground process [on hold]

A shell script to find out PID of current shell and number of positional parameter and PID of last background process.
3
votes
3answers
157 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 ...
1
vote
2answers
36 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
54 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 … ...
2
votes
1answer
64 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
50 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
63 views

convert CSV to XLS file on linux [on hold]

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 ...
3
votes
1answer
109 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 ...
2
votes
1answer
67 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
71 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
26 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
56 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
28 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
53 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
36 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
43 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
20 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
48 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
51 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
18 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
59 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
34 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
49 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
115 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
39 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
531 views

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

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
32 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
17 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
28 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
34 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 ...
1
vote
1answer
46 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
9 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
616 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 ...
-1
votes
1answer
42 views

Grep Command not working inside script [closed]

Below command when executing as comand is working.. same while executing inside script not executing.. grep '^1' $Source_path/$File_name > $Target_path/XYZ_${Cntry_code}_RECTYP_1.dat if am ...
0
votes
2answers
17 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
40 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
32 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 [email protected] -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
68 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
72 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;}'` ...
-2
votes
0answers
33 views

Simple shell script [closed]

So I need some help with writing a simple shell script that will allow a user to display a list of current users. It isn't homework and i'm not looking for a completed code, just help to how i'd go ...
-1
votes
0answers
27 views

Update file values with another file [closed]

I have a file named /work/Target/IB/USSALESCOMP/ODS_INCR.prm as below $$Firm_INCR_DATE=09/05/1992 $$Branch_INCR_DATE=01/01/1900 $$Payee_INCR_DATE=01/01/1900 $$PRODUCER_INCR_DATE=01/01/1900 I ...
1
vote
2answers
84 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 ...
5
votes
2answers
340 views

Using grep in a if-else statement [closed]

Why my code isn't outputting if a string entered isn't in the file. When I enter a string and it isn't in the file, there's no response back, it re-loops back to the beginning. Can someone tell me ...
3
votes
1answer
26 views

More shell scripts than one in one text file?

I am learning shell scripting for my introductory UNIX course at my university, and I`m curious if is it possible to have more than one shell script in one text file. What I mean by that is, for ...
0
votes
3answers
162 views

How to add a password to a specific command

I've been searching google on how to add additional security to a specific command without using sudo. Is it possible to add on a security feature without actually using sudo? For example: Whenever ...
2
votes
1answer
31 views

Single or double brackets and portability

I have found some very good answers here on the differences between [ and [[ in 'if' statements. For specific named shells, it seems to be a good idea to use [[ over [ (and it is faster, too). I'm ...
0
votes
0answers
39 views

Loading csv data into hbase table in multiple columns using flume [closed]

Is anyone know how to sink spool directory's .csv file data using flume to hbase i.e splitted columns into the hbase ? CSV File Format Data is: sample.csv ...