I have the following script
=========
=============
What i want is - if there is a mutex file like /tmp/.test or /tmp/.globallock, the script should exit.
However when i run without the mutex file - it runs fine. But when i create a mutex file - like /tmp/.test - it does not exit out and executes the "after for loop" echo statement before exiting.
What am i doing wrong?
Last edited by GosarJunk; 02-15-2012 at 07:26 PM..
Reason: please use code tags
The operators ! and -o work in [], but as I recall the ! is not evaluated to just the following, first predicate, but to all unless in \(\), which is getting busy. I just avoid getting too fancy in [].
I like 'if' or 'case' when a condition is being tested, not "logic as procedure". You can, but should you? For one thing, if/case allows you to drop in debug statements easily, if you get lost.
The script can be much simplified and many scripting errors removed.
One bug is on this comparison:
Quote:
"$MUTEXPREFIX.${m}"
Assuming that the array assigment works (it actually gives a syntax error in my Posix Shell) you would be generating filenames /tmp/.test and /tmp/.globallock (note the embedded full stop).
There is never a reason to end a unix Shell command line with a semi-colon. This is unix not Oracle.
You "if" test is overcomplicated but it might work. Better to keep it simple so everybody can follow your code.
Last edited by methyl; 02-15-2012 at 04:32 PM..
Reason: correct echo. There's nothing useful in $0.
Sorry my bad - i updated the original post where i left the "." in the filename for Mutex.
The "." is correct - since we will be having /tmp/.test or /tmp/.globallock file - hidden files.
The code works fine until i put in a "echo "$0 Mutex file found - exiting" to get into an error log.
This below code works fine ...
======
======
for simplicity sake - in our example here - i m doing an "echo" instead of writing to a file.
---------- Post updated at 03:31 PM ---------- Previous update was at 02:55 PM ----------
I did a "sh -vx" to deebug this script. For some reason it does not execute the exit 1 - which is in the code.
=======
=======
---------- Post updated 02-16-12 at 10:30 AM ---------- Previous update was 02-15-12 at 03:31 PM ----------
Any idea why it would not execute the "exit 1" statement ?
Any Unix shell scripting gurus?
Last edited by Franklin52; 02-16-2012 at 03:35 AM..
Reason: Please use code tags for code and data samples, thank you
I need to check whether the directory is exist or not. only three letter will be passed as argument. from that it should pick the entire directory.
Instead of banking and manfucuture the input will be passed as man or ban.
$1 -> ban $2-> monday
#!/bin/sh
DIR='/sales/$1*/monday'
if ;... (3 Replies)
Hi all,
can you plz check whether the below code is correct & some inputs.
I need to read the below file and process it.
input :
/home/ibm/var.txt
urgent
not urgent
not needed.
#!/usr/bin/ksh
VAR=/home/ibm/var.txt
if ]
then (7 Replies)
Unix script coding help?
i am trying to write a code that will display following menu to user:
(A) Add
(B) Subtract
(C) Multiply
(D) Divide
(E) Modulus
(F) Exponentiation
(G) Exit
Then ask user for choice (A-F). After taking users choice ask user for two numbers and
perform... (0 Replies)
Hello,
I am a new Unix user and new to shell programming. I am working on a script to go through a log file and find the text error:
grep -i 'error' monplus.mplog
if I find the text error in the log file I would like to echo a message to the operator staing there is an error
I am currently... (2 Replies)
hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?!
echo "enter a number "
read n
i=0
first=0
second=1
result=0
prime="true"
echo –n " $first $second "
while
do
result=`expr $first + $second`
first=$second... (10 Replies)
Hiiiiiiiiiiiii all,
Please i want your help fast, the teacher gave us this assignment can u help me to write it?
this is the question:
Write a shell script to point all prime numbers from the fibonacci series of integer N?
using Red hat Os
Thanks all and waiting for ur answers... (1 Reply)
when i run a shell script i have to type
./my_prog
and the first line of my_prog has to have
#!/usr/bin/env bash
how do i change it to i only have to type my_prog to run it? (4 Replies)
Hi,
I have a file say xmldir.conf. This is a flat file which contains the data in specific format not other then this. The format is
/backup/surjya/mvfile,noeof
/backup/surjya/mdbase,eof
/backup/surjya/mdbaseso
/backup/surjya/trial,hoeof
/backup/surjya/test,eof
The field before "," is... (2 Replies)