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

learn more… | top users | synonyms (2)

2
votes
3answers
28 views

Does it make a difference (e.g. performance-wise) if I execute a command from a bash script (vs the command line)?

Is there any difference between the following (e.g. performance-wise): $ make && cp bin/myexecutable inputfile.txt $workdir && cd $workdir $ <series of sed commands to modify ...
1
vote
2answers
33 views

How to print file content *and delete printed content* from file?

In Linux bash shell, How can I print file content and delete printed content from file? I have a program writing texts to a file repeatedly. On a Linux shell prompt, I want to print the contents of ...
2
votes
3answers
1k views

Query list of servers for memory/cpu allocated

Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format: HOSTNAME1 CPUS: 12 ...
2
votes
2answers
69 views

How to remove duplicate files using bash

I have a folder with duplicate (by md5sum (md5 on a Mac)) files, and I want to have a cron job scheduled to remove any found. However, I'm stuck on how to do this. What I have so far: md5 -r * | ...
0
votes
1answer
50 views

tar unused files then delete them

I have folder with subfolders and sessions logs. I need some commands or script to tar this folder without usage files and then delete it. I have this construction, but I'm not sure if this leave ...
1
vote
3answers
34 views

CSV Units Conversion

I've got a CSV file that looks like the following: miami,20,in lansing,2,cm austin,3,mm chicago,5,miles phoenix,2,feet The first field is the name, the next field is the numeric value and the third ...
6
votes
6answers
13k views

gpg asks for password even with --passphrase

I expect the following command to extract the gpg file without asking for password: gpg --passphrase 1234 file.gpg But it asks for the password. Why? This also have the same behavior: gpg ...
-3
votes
0answers
33 views

Convert file pattern in Unix

I have a file with content as below 31/01/2014 1234 2234 4567 3321 ...n Need to write a shell script to convert the above file as below: DD_Date='31/01/2014' ...
1
vote
3answers
69 views

Find result used in if statement

How can I use the result of a find command in an if statement and compare with true or false? Something like this: if [ `find . -name test.txt -size 156c`="true" ]; then echo Found; fi This is ...
0
votes
1answer
1k views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
1
vote
1answer
39 views

Write text on last line of document [duplicate]

If I have this document aaa bbb ccc And I want to add " ddd" on the last line. My document should look like this: aaa bbb ccc ddd How can I do this? If I prefer awk or sed but ...
17
votes
7answers
16k views

How to get my own IP address and save it to a variable in a shell script?

How can I get my own IP address and save it to a variable in a shell script?
2
votes
1answer
89 views

grom() keyword in bash throws unexpected '(' token

I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that ...
0
votes
2answers
39 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
3
votes
2answers
109 views

How to list only JPEG files from root below using the command line?

I am searching for a method to find only JPEG files/ With my limited knowledge of Linux I came to this point: list all paths that exist from root below with find / pipe the result into next command ...
1
vote
1answer
52 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
0
votes
2answers
45 views

Adding 1 string to end of file, Even when ran multiple times to change MD5

I need to change the md5 of my files, Sometimes once, sometimes multiple times. A friend gave me this script to add a string to the end of the file but i think i may be adding it multiple times when i ...
1
vote
1answer
528 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
35 views

User Input Bash Script

I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could ...
3
votes
1answer
85 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. ...
0
votes
4answers
3k 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
vote
2answers
29 views

Read file remove spaces and store in array

I have a file with the following content: list: blue,none red,none orange,plot baseball , none university,none school,none desk,plot monitor,none earphone,none I need to read this file, ...
0
votes
2answers
97 views

Shell script to execute psql command [on hold]

I want to make an automated script to make a database user and password in Postgresql and also import some databases. When i execute my script bellow it stops somewhere and when i log out (CTRL+D or ...
0
votes
0answers
27 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
4
votes
1answer
44 views

Why does 'jobs' always return a line for finished processes when run in a subshell within a script?

Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 ...
1
vote
1answer
30 views

Search for text inside java command output

I have a folder which have multiple Jar files. * dummy.jar * myjar-xx.jar * myjar-yy.jar Using find, I need to find first file starting with "myjar" Now, I want to grep the contents of ...
2
votes
1answer
22 views

how to connect automatically to a saved list of networks

I want to make my Debian laptop connect automatically to a list of stored WiFi networks in a text file that have the syntax SSID:password, using a non graphical way (script or config). These networks ...
0
votes
1answer
43 views

Can a command in a shell pipeline determine the tty characteristics of its context?

I have a bash script that columnizes a list of items. By default it will guess at the number of columns to output, based on the terminal width as reported by stty size. But when the script is in a ...
0
votes
1answer
38 views

What's a way to get the first network interface using grep in ifconfig? [on hold]

Just trying to figure this out for a System Administration introduction course, and I can't seem to get it.
4
votes
4answers
325 views

How to fill a file with a stream from /dev/urandom with a specified number of lines ?

I am trying to fill a file with a sequence of random 0 and 1s with a user-defined number of lines and number of characters per line. the first step is to get a random stream of 0 and 1s: cat ...
7
votes
10answers
4k views

Decoding URL encoding (percent encoding)

I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this? I did search a bit through unix.stackexchange.com and on the ...
3
votes
1answer
331 views

Strip most frequent words from text

I have a simple problem, but unfortunately I don't know where to even start (I'm just starting out). So, what I want to do is ultimately increase my vocabulary. I got the idea to strip the most ...
1
vote
2answers
618 views

Command/scripts to check the Reverse DNS Lookup time

I am working on a project in which one master communicates with numbers of slaves. For that it has to make connection with hosts in network. But sometimes it hangs. I think that the reason behind is ...
-1
votes
0answers
23 views

Inserting a text file into a script using cyg-win- did i not claify it well enough? [on hold]

I am writing a script that checks for directories, if they are not there then it is to create them. In two of the directories i need to insert a text file. One of the files has eight comment line and ...
3
votes
2answers
101 views

Nested 'awk' in a 'while' loop, parse two files line by line and compare column values

I need some help with a combination of awk & while loop. I have two simple files with columns (normal ones are very large), one representing simple intervals for an ID=10(of coding ...
-1
votes
0answers
40 views

No Such file or Directory 4 [on hold]

throw the script posted in this question link syntax error near unexpected token `)' I get this error: test.txt: No such file or directory 140308719470240:error:02001002:system library:fopen:No ...
0
votes
1answer
24 views

sepration of files on the basis of there name

I have a folder containing lots of files like 3 lac plus files. I have to separate them according to their names in three different folders. e.g. a few names are: 7msf_stem_0_mcannotate.pdb ...
1
vote
1answer
150 views

how to check the string is Null or not in shell script? [on hold]

I had a script like this #!/bin/bash line="hello" if [ -z $line ] ; then echo "String null" fi This will work properly, but when I give the lineas follows ...
10
votes
3answers
5k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 ...
0
votes
0answers
49 views

Where is the log_daemon_msg?

So this is my little shscript (my_init_script.sh) located in /etc/init.d/ #!/bin/sh . /lib/lsb/init-functions NAME=my_script_for_auto_update PIDFILE=/var/run/$NAME.pid ...
1
vote
1answer
31 views

Using parameters in a script

I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command: for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...
1
vote
1answer
35 views

Test for open TCP port in bash script

I want to delay the script execution until a certain server process is ready, which it is once it accepts incoming TCP connections. How do I test if a local TCP port is open (I get a SYN/ACK answer)? ...
1
vote
2answers
20 views

Script using sudo works from a terminal but not from a desktop shortcut

I create small script to mount encfs filesystem. just like this: #!/bin/bash kdialog --password "Wprowadź hasło do SSH lub ENTER żeby rozłączyć:" > /home/maciek/Pobrane/pass-1 sudo encfs -S ...
4
votes
2answers
544 views

How do I run a script when I switch between keyboard layouts

I use more than one keyboard layout, and I would like to find a way to run a script when I switch between them. Is this possible? So far, I can assign a shortcut for a script like this: #!/bin/bash ...
3
votes
3answers
86 views

Delete folders which not match a list

I need practical example how get rid folders which are not in the list in Linux. So i do not need to compare its contents or md5sums, just compare folders names. For example, one folder has few ...
0
votes
2answers
47 views

Input in bash script

I have a script like this: for i in *.TF; do my command $i done The problem is, each command line needs a same input (in this case: /PS) how can I do this? I have tested some methods like: /PS | ...
3
votes
3answers
12k views

Loop over a file and read values from two columns into variables

I have a file (data.dat) which contains 3 columns. I want to read in two of them with the shell script and fill the contents into a template file. The file looks like this: 12 180 2390 14 177 2210 16 ...
-1
votes
1answer
29 views

AWK and Bash Scripting [duplicate]

How to use a value of a variable in awk? Something like this: filename = "test.txt" ls -l | awk '{ if ($9 == filename) print("File exists")}' I can't use $ in awk to access the value of ...
0
votes
4answers
865 views

How to get data count between two strings with multiple occurences in the same file

I have the data in my file as START-OF-FIELDS ID NAME DEPT END-OF-FIELDS START-OF-DATA 1|joy|cs 2|sam|ec END-OF-DATA START-OF-FIELDS ID NAME DOB DEPT ADDRESS END-OF-FIELDS START-OF-DATA ...
0
votes
1answer
20 views

Cron start script twice

I have a backup script which sends my snapshots to a off-site location. 0 0 * * * /root/backup/backup_incremental >> /root/backup/test.log For some reason my PID file which should stop the ...