shell-scripting

Trying to test space in filesystem on Unix

I need to check if I Filesystem exists, and if it does exist there is 300 MB of space in it. What I have so far: if [ "$(df -m /opt/IBM | grep -vE '^Filesystem' | awk '{print ($3)}')" < "300" ] then echo "not enough space in the target filesystem" exit 1 fi This throws an error. I don't really know what I'm doing in shell. My highes...

"/bin/sh 'ls -l -R'" vs "/bin/sh -c 'ls -l -R'"

What is the difference between the following two commands, when run on AIX? /bin/sh 'ls -l -R' /bin/sh -c 'ls -l -R' ...

Why does the wc utility generate multiple lines with "total"?

I am using the wc utility in a shell script that I run from Cygwin, and I noticed that there is more than one line with "total" in its output. The following function is used to count the number of lines in my source files: count_curdir_src() { find . '(' -name '*.vb' -o -name '*.cs' ')' \ -a '!' -iname '*.Designer.*' -a '!'...

Sed script command truncating last line

I'm trying to remove the carriage returns (\r) from a file with the following command on AIX, but it's also removing my last line. Any suggestions? sed -e 's/\r\n/\n/g' ./excprule > ./excprule.tst Command sequence: dev1:> sed -e 's/\r\n/\n/g' ./test_file > ./test_file.tst dev1:> diff test_file.tst test_file diff: 0653-827 Missing n...

Why does my shell script not find anything (find . -name script.sh | grep watermelon)

I have a script that I'm running from the home directory to search for all files called "script.sh" that contain the string "watermelon". It's not finding anything but I can clearly see these scripts in the subdirectories. Could someone please suggest a change to the command I'm using: find . -name script.sh | grep watermelon ...

shell script passing subset of arguments

From the wrapper shell scripts i am calling the Java program. I want the Unix shell script to pass all the arguments to java program except the EMAIL argument. HOW Can i remove the EMAIL argument and pass the rest of the arguments to the java program. EMAIL argument can come at any position. valArgs() { until [ $# -eq 0 ]; do ...

replace a particular text in all the files using single line shell command

i have a renamed js file which i have to call in each of my php page. Now i want to replace that old name with the new one using shell. what iam using is this :- sed -i ’s/old/new/g’ * but this is giving the following error :- sed: -e expression #1, char 1: unknown command: now how can i do this replacement?? ...

How can I get the associated ref path for a git SHA?

Hi, I want to be able to pass anything to a git command (maybe its a SHA, maybe it's just something like "origin/master" or "devel/epxerimental" etc.) and git tells me the ref path of the branch that the passed something lives in, e.g. <git_command> 0dc27819b8e9 => output: refs/heads/master <git_command> xyz/test => output: refs/remote...

unix shell script - extract file name

I have a variable which has the directory path along with file name. I want to extract the filename alone from the unix directory path and store it in a variable fspec="/exp/home1/abc.txt" ...

deleting a directory in solaris,Ksh

rm -r /cbbconfg/BRCH/tmp rm: cannot determine if this is an ancestor of the current working directory ...

Regarding UNIX Shell Script

When there is no files inside the folder the below script goes inside the for loop. Not sure what i can modify so that it doesn't go inside the for loop. Also when there is no files inside the directory exit status should be success. Wrapper script checks the exit status of the below script FILESRAW ="/exp/test1/folder" . for fspe...

Regarding Unix shell script

I want to retrieve the file from the INFILE directory which are begining with the file names prefix "BBSCGG_" or "BCT_" or "ACL_" or "ASC" and do the processing inside the for loop INFILE=/ext/test/fil1/ for infile name in file prefix ... if [[ -f ${fspec} ]] ; then processing logic else proc...

what is wrong with this shell script

market_l="${echo $1 | awk '{print tolower($0)}'}" echo $market_l when i execute this its giving me an error below: ./test: market_l="${echo $1 | awk '{print tolower($0)}'}": The specified substitution is not valid for this command. ...

Restoring/Restarting a java daemon from crash

Hello, I am running a java app as daemon on a linux machine using a customized shell script. Since I am new to java and linux, I want to know is it possible that the app itself resurrects itself(just like restart) and recovers from cases like app crashing, unhandled exceptions or out of memory etc. thanks in advance Ashish Sharma ...

bash: getting rid of '.' and '..' when looping over files that begin with '.' in a folder

I want to loop over the files that begin with '.' in directory x (x might be any path): $ for file in x/.* > do > echo -n $file" " > done x/. x/.. x/..a x/.b What is the best way to get rid of x/., and x/.. ? ...

this one-line shell script not working on Mac - any ideas how to fix?

Hi, This unix command I haven't got quite working on Mac yet - any ideas what needs adjusting: find . | grep '.*\(css\|js\|rjs\|rhtml\|rb\)$' | sort | while read in; do printf "\n\n####\n# FILE: %s\n####\n\n" ${in} >> onebigfile; cat "${in}" >> onebigfile; done thanks ...

How this regular expression is working

I found a script which has the following snippet:- userid=`expr "\`id\`" : ".*uid=[0-9]*(\(.[0-9a-z]*\)) .*"` It returns the userid. When i tried to learn how it is doing:- #id #uid=11008(adilm) gid=1200(cvs),1400(build) So I realized that (.[0-9a-z]*) is matching the userid. But if I placed like below: #userid=`expr "uid=11008(A...

Missing output when running system command in perl/cgi file

I need to write a CGI program and it will display the output of a system command: script.sh echo "++++++" VAR=$(expect -c " spawn ssh -o StrictHostKeyChecking=no $USER@$HOST $CMD match_max 100000 expect \"*?assword:*\" send -- \"$PASS\r\" send -- \"\r\" expect eof ") echo $VAR echo "++++++" In CGI file: my $command= "ksh ../cgi...

Shell script to name videos on device

I have a .sh script that automounts any usb device that is plugged in. I need it to also find if there are videos in a certain location on the device that is plugged in then write them to a videos.txt file. Here's what I have and its not working. Also I need it to put the mountpoint in the videos.txt file. ${MOUNTPOINT}$count is the path...

Tool to create UI for Linux (Gnome) shell scripts

I'm writing a bunch of Linux shell scripts with complex selections. For now I use zenity for prompts. I'd rather use something where I can show more than one UI element at a time and query it in a script (e.g. a list and some checkboxed and a file picker and an entry field. What are my options? ...