Tagged Questions

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

learn more… | top users | synonyms (2)

1
vote
1answer
44 views

case multi-pattern with strings

If a put "TITI" or "TETE" on V3 it doesn't work but "TOTO" will work. It's like it takes into account only the first possibility..."TOTO". #! /bin/ksh - V1=CRITICAL V2=HARD ...
1
vote
1answer
40 views

Does the command execute automatically when setting it to a variable?

I'm getting familiar with all about linux & shell/bash scrpiting. I'm configuring a backup script & it will compress an entire dir. I wanna know if I have to print the variable where the ...
1
vote
2answers
138 views

can you only input the password once and then execute the su command without entering a password? [duplicate]

I am copying files from a remote server to my local server. Here is the code that does this: sshpass -p "password" ssh -q username@$192.168.162.156 "mkdir -p /temp ; ...
1
vote
1answer
82 views

Using kornshell or Perl to circumvent permissions needed by root

I have a problem where I need to change the ownership and permissions of one file that exists on more than 200 servers. I belong to 2 different groups and need to change the ownership from one group ...
0
votes
3answers
2k views

compare two files based on a column and print it

I have two big files of 400,000 lines. I want to compare the column 1 of the second file with column 1 of first file recursively. If they match I would like to print the whole line. It is a sorted ...
1
vote
2answers
409 views

Shell script to Capture the file name and size in csv file and add header on that file

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 ...
2
votes
2answers
242 views

Any way in Bash to write to a file every X seconds without closing it?

The hardware watchdog on my system needs a 0 written to /dev/watchdog at less than 60 seconds interval or it will fire. The file handle must be kept open however or the watchdog is then disabled. ...
5
votes
2answers
164 views

How exactly does `if $cmd ; then $cmd ; fi` differ from `$cmd && $cmd`?

In an answer to another very good question I made the following assertion: According to my reading of the POSIX specs, the use of one or the other makes no difference from a parsing standpoint. ...
9
votes
4answers
1k views

Bash syntax error when “else” follows an empty “then” clause

Why would following script not execute, but give a syntax error of else: LOGS3_DIR=~/logs if [ -d "$LOGS3_DIR" ]; then cd cd "$LOGS3_DIR" echo "$LOGS3_DIR" for filename in `find "." -mtime 1 ...
1
vote
1answer
31 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
44 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
486 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
65 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
106 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
100 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
221 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 ...
3
votes
2answers
111 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
203 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
106 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
219 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 ...
0
votes
1answer
904 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
434 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
159 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
419 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
837 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
159 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 ...
5
votes
3answers
4k 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
152 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
222 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
52 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
373 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
171 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
126 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
2k 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
96 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
423 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
411 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
422 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
304 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
116 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
178 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
455 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
48 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
202 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
297 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
46 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
154 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
94 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 ...
22
votes
3answers
2k 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
123 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 ...