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

learn more… | top users | synonyms (2)

1
vote
1answer
43 views

Sourcing scripts with a for loop for different variables

I have several shell scripts that I summarised within a global script. I am using some variables that are the same across all scripts, and I wrote a separate script for this, which I am sourcing in ...
3
votes
1answer
55 views

Redistributable completion for my bash scripts

Is there a simple way to embed the completion features inside a script, for bash ? I have a script that I want to redistribute, but I can't ask the people to add something inside their ...
3
votes
2answers
568 views

Read all files in folder and subfolders - progress and size

Command I have is: time find . -type f -print -exec cp {} /dev/null \; This command finds all files in current folder and subfolders, print the name of each file and copy each of them to /dev/null. ...
-1
votes
1answer
162 views

Cron spamming because of renice [closed]

I have a bash script that I execute using cron. The script begins like this: #! /bin/bash DIR=/home/pi/bin/run renice 19 -p $$ ionice -c 3 -p $$ : Now, every time cron runs this script it sends ...
0
votes
1answer
179 views

Writing a shell script in Ubuntu to process several layers as a single animated GIF file [duplicate]

I am an Ubuntu 12.04.4 LTS 32-bit user and I would like to automate the process of opening several PNG images as layers then saving these layers as a single animated GIF file in the GUI of GIMP. My ...
4
votes
2answers
122 views

Remove specific file from directory if it's the only one

I have a lot of directories and sub-directories. I want to recursively remove one specific file from a directory if it's the only one there. Also assume that there are no sub-directories in that ...
1
vote
1answer
281 views

Shell script and crontab to capture file size, name and date in a CSV file and then send via email?

I have a number of zip files in a certain folder. I want to capture file name and the size of the files in a CSV format in day wise and put it in crontab so I can report on a daily basis, and then ...
6
votes
2answers
305 views

Have ssh-add be quiet if key already there

I want to put ssh-add /path/to/special_key at the top of a script. This works fine, but it always prompts for the passphrase. This is strange, and a little annoying, as it still asks for the ...
1
vote
4answers
300 views

Add/delete workstation ip to /etc/sysconfig/iptables and then run service iptables reload

I need a script to add a users workstation ip to /etc/sysconfig/iptables and then run a service iptables reload. I need the same type of script for removing this rule from iptables. I found the ...
1
vote
1answer
164 views

Copy the file created newly in UNIX [closed]

I have a directory where so many files created daily and need to copy the new files which were generated. And all files will be created with starting name abc_ Ex:I have a file abc_0520123.pdf on ...
2
votes
1answer
1k views

Sharing variables across multiple shell scripts

I am trying to summarize multiple shell scripts within one large shell script, such as this: #!/bin/sh bash script1.sh bash script2.sh bash script3.sh All scripts share the same variables "var" and ...
1
vote
1answer
2k views

two .csv files compare using awk

I need to compare two files, File1.csv and File2.csv (Separated by ',') using Awk Logic: Column PID in both files are reference. If for same 'PID' in 'File1.csv' and 'File2.csv' and in both files ...
2
votes
3answers
2k views

How do I drop root privileges in shell scripts?

The "--up" option in OpenVPN is normally used for routing etc. And so it is processed before OpenVPN drops root privileges to run as nobody. However, I am invoking shell scripts that need to run as an ...
0
votes
2answers
266 views

Simple Script to setenv tcsh or export bash

I am having problems with simple scripting, my Box is CentOS so bash is the default shell, now I wanted to send a line via setenv (tcsh) and would like to make a script that will ask me to input a ...
5
votes
4answers
624 views

how can we use awk to get multiple words after a significant word?

I want to connect to my DB only once to do multiple SELECT queries as follows: #!/bin/bash #Begin Code query=$(echo "SELECT COUNT(*) from USER_IPTable; SELECT User from USER_IPTable; ...
1
vote
1answer
5k views

Switch users with sudo or su in a shell script

I inherited this. Long story short I have an XML file that is calling a shell to run some commands. Everything I have tried has failed at the second su in the script. Here are some of the failure ...
2
votes
3answers
277 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
8
votes
3answers
8k views

Prompt user to login as root when running a shell script

The problem I am getting is, when I enter the command, su - root at the beginning of my shell script file, it prompts the user to enter the password and then does NOT continue with the rest of the ...
5
votes
2answers
173 views

What does ${3#?} do?

I have a script with the following variable assignment: TEST_VARIABLE=${3#?} What does the ${3#?} do?
1
vote
2answers
304 views

Run jar on startup in all *nix based systems

I have a jar file which I need to run at startup in all distros of Linux. My previous question here, gave me an idea a rough idea on X-servers. Since I wasn't able to perform startup, I moved on to ...
0
votes
2answers
63 views

SSH using diff and still not working

I have 2 file, a.txt and b.txt and I want to compare them. a.txt contains: abc jkl < jkl mno > mno pqr <> pqr b.txt contains: abc jkl < jkl mno > mno pqr <> pqrs stu I'm ...
1
vote
4answers
2k views

How do i get the latest file from a list of files in a particular directory

I need to get the latest file from a list of files in a particular directory. When I run the script the first time I've copied the list of files in a particular directory to another directory. From ...
3
votes
2answers
313 views

Header function with increasing number in bash

I would like to have a function in bash that I can use in some install scripts to announce that the next paragraph is starting. A simple solution (with colors) would be headline(){ echo -e ...
1
vote
0answers
269 views

Changing KDE's mouse theme and buttons settings from a shell script

I'm trying left handed mousing, and I want to be able to easily switch between right handed mode and left handed mode. There is a utility for Windows called SwapMouseButtons that allows to bind a key ...
6
votes
10answers
4k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
0
votes
2answers
173 views

shell or python script to transpose rows to columns [duplicate]

I have a big file with numbers like: 1 2 3 4 5 6 7 8 9 9 9 9 I want to tranpose it into 1 5 9 2 6 9 3 7 9 4 8 9 I have search on google for solutions, but those solutions simply don't ...
9
votes
1answer
832 views

communication between multiple processes

I have a bash script, which runs manager() function as a separate process for x-times. How is it possible to forward messages to all manager() processes from within the script? I've read about ...
4
votes
1answer
2k views

Automatically detect when a file has reached a size limit

I would like to send an email when a file reach a certain size limit. The only way I thought of doing this is by doing a cronjob which will check the file size and send the email if the file is ...
2
votes
1answer
1k views

syntax error: unexpected end of file

#!/bin/csh -f set no=1460 while ("$no">0) if [$no>900]; then set m=3 else if ["$no">450 && "$no"<901]; then set m=2 else set m=1 fi mv *$no.bin test/abc-$m-$no.bin set no ...
0
votes
3answers
606 views

Unix commands for generating random alphabet [closed]

I have to write a script for this program. choose a random letter within a-z. Ask the user to guess the letter, match it with the chosen letter. If matched, display "correct", else prompt if the ...
1
vote
1answer
240 views

grep and command-line variable substitution

In the following command sequence, $ grep -E '^.{11,22}John' emplist Operations John Thompson PARTHawks Cher Sales John Jacobs FULLHawks Davinder Singh Finance ...
2
votes
2answers
277 views

Find and rename files adding part of the path to filename

I have a folder with two level of subfolders inside it. Inside the second subfolder, there is a jpg file. All the jpg have the same name: cover.jpg Example: /home/user/folder001/folderAAA/cover.jpg ...
1
vote
1answer
1k views

Interpret an interpolated variable as a literal string in Perl regex

I am using perl to colorize a matched string MATCH=aaa printf "aaa\n/dev/aaa\nccc\n" | perl -pe "s/($MATCH)/\e[1;31m\1\e[0m/g" This works well until I try to match a string containing special ...
1
vote
1answer
59 views

How to Test if a file has characters in it?

So i have a part of this code and U want it to output "No such player" if only the names file is empty, i've tried using the test -s command but it gives an output of 0 even if the file is empty or ...
2
votes
3answers
296 views

conditional coloring in grep

I have a simple bash script. One line of my script matches a "pattern" with grep and colors the match grep -i --color=always -- "$1" I need to modify it, so that it only colors the match, if the ...
1
vote
1answer
788 views

getting list of children processes by a background shell function

I have a bash script, in which I call function in a background: process_manager $1 $2 $3 & The function runs / executes commands that are passed as an argument in the background. How can I get ...
0
votes
1answer
51 views

For output weird

This is my script: #!/bin/bash E=0;j=0 for i in A B C do Erray=$(sed -n '/Local net energy/p' log | awk '{print $7}') A[j]=j echo $i = $Erray kJ/mol >> Energy let j=j+1 echo $j $i ...
2
votes
1answer
264 views

How to create an executable bash script for these commands?

I wish to create an executable bash script that will run the following commands as root, that is, using sudo su iptables-save | awk '/^[*]/ { print $1 } /^:[A-Z]+ [^-]/ { print ...
1
vote
2answers
148 views

Stop netcat when VirtualBox closes

Using netcat to redirect print output from DOS program in VirtualBox under OSX. #!/bin/bash VBoxManage startvm FreeDOS while : do nc -l 1235 | lpr done This works except that when VirtualBox ...
48
votes
3answers
17k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
1answer
166 views

Bash script in RHEL to add/remove users in iptables [closed]

I will try to reword this as best as I can. I created a virtual machine to serve as a loadtest server with RHEL. If a user requested access to this server to run a loadtest, his workstation ip would ...
4
votes
3answers
2k views

replace column of a csv file with column from another file

I have two sample files like this: $ cat file1 abc,sachin cat,kumar $ cat file2 xyz pressure $ cat file3 xyz,sachin pressure, kumar I want the first column of file1 to be replaced with file2. ...
0
votes
0answers
17 views

Free DNS Clients [duplicate]

I have a Synology server 213. I host my own sites and every month I have to update my dns. I use freedns. I have noticed that you can get scripts that check your ip and hopefully update it when it ...
1
vote
1answer
2k views

Shell script to perform telnet session to ser2net

I have setup a xenserver (free) hosting a VM (Debian 7.5). On this xenserver I have attached a serial GSM modem. I have configured xen to run ser2net so I have a serial proxy available. This works ...
0
votes
1answer
530 views

Unable to move files with SFTP

I'm trying to move files from one location to another on the remote server using sftp below: for i in a b c d do sftp $REMUSR <<EOM>>$OUT 2>&1 rename ...
1
vote
2answers
509 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
3
votes
3answers
4k views

'is a directory' error when trying to pass directory name into function

Note: I am a newbie to bash scripting In my bash script, I use find to get the folder names by wildcard: for i in $(find ${directory} -mindepth 1 -type d -name ${wildcard}); do stuff=doStuff ${i} ...
1
vote
1answer
59 views

Use a bash function in a pipelined command

I have a command similar to: ... | sort -u -V. Since some versions of sort do not support the -V flag, I thought it would be great if I made a function that conditionally adds the flag. But, it seems ...
4
votes
2answers
3k views

Is there a GUI debugger for shell scripts

Debugging bash scripts on command line is complicated. Is there a good GUI based debugger available for debugging bash scripts?
3
votes
1answer
3k views

if else statement in one line using && and ||

I would like to know if these 2 ways are equivalent: First: #!/bin/bash if [ -x $FILE ] then echo "You have execution permission to a "$FILE"" else echo "You don't have execution permission to a ...