Question about Setting Flags


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question about Setting Flags
# 1  
Old 04-11-2008
Question about Setting Flags

I have a script which will look for a test folder under the parent directory. If the folder contains test folder then create the same directory structure in other remote machine.

Once the directories are created then transfer all the contents of that test folder.

this is what i am doing :-

Code:
LOG_FILE_DIR="/home/chris/" 
   LOCAL_LOG_FILE=$LOG_FILE_DIR/"server_`date +%m%d%Y`.log" 
   SENDMAIL=0 
   MAIL_FILE=tmp.txt 
   REMOTE_DIR="/home/john" 


   cd /home/mike
   for dir in *; do
   if [ -d ${dir}/"test" ]; then

   /usr/local/bin/ssh -l melo ferrari "mkdir -m 777  $REMOTE_DIR/$dir" >>$LOCAL_LOG_FILE 2>&1
   STATUS=$?
   echo "Status = $STATUS"
   if [ $STATUS != 0 ]; then
   SENDMAIL=1
   echo "Cannot create directory $dir " >> $MAIL_FILE
   fi

   scp -r ${dir}/"test" ferrari:$REMOTE_DIR/${dir}/
   TESTING=$?
   echo "Testing = $TESTING"
   if [ $TESTING != 0 ]; then
   SENDMAIL=1
   echo "Cannot SCP for $dir " >> $MAIL_FILE
   fi

   fi 
   done

   if [ $SENDMAIL != 0 ]; then
   mail -s "Script Failed" chris1234@hotmail.com <$MAIL_FILE
   fi
   
   exit 0

The first time the script runs the value for STATUS is 0 but the second time the script runs the value for STATUS is 2. The first time directories are not created in the remote machine that is why the value for STATUS IS 0. The second time the value is 2 because the directories already exist in my remote machine.

So because of the value for STATUS is 2 i always get an email that "It failed to create the directory" because the directory already exist.

How can i get rid of that STATUS = 2 value? I mean is there any alternative?
# 2  
Old 04-11-2008
It's your script, you can make it not fail if the error is non-fatal.

Having said that, the easy workaround would seem to be

Code:
/usr/local/bin/ssh -l melo ferrari "test -d $REMOTE_DIR/$dir || mkdir -m 777  $REMOTE_DIR/$dir" >>$LOCAL_LOG_FILE 2>&1

Also note that anything along the lines of

Code:
command
STATUS=$?
if [ $STATUS != 0 ]; then ...

is just a very clumsy way to say

Code:
if command; then ...

unless you specifically need to have side effects such as STATUS being equal to the exit code of that command regardless of whether it succeeded.
# 3  
Old 04-11-2008
Era thanks. Usually i do :-

Code:
if[ ? != 0 ]; then
SENDMAIL=1
.
.

Anyways i tried your solution era the value for STATUS is still 2 for the second run. So in other words i still get the email because the return value for the mkdir -777 command is not 0. It's 0 only the first time when it runs.

The second time is 2 because the directories are already created in the remote machine and it tries to create it again.

I have been searching on google for this problem but not yet lucky.

Code:
/usr/local/bin/ssh -l melo ferrari "test -d $REMOTE_DIR/$dir || mkdir -m 777  $REMOTE_DIR/$dir" >>$LOCAL_LOG_FILE 2>&1

Not working
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

View file flags

hello: how could i view the file's flags? "ls -loa" doesn't seem to do the trick: root@giraffe:/etc # ls -alo total 820 drwxr-xr-x 23 root wheel - 2048 Oct 23 19:48 . drwxr-xr-x 19 root wheel - 1024 Nov 16 15:01 .. drwxr-xr-x 2 root wheel - 512 Nov 11 2014 X11... (6 Replies)
Discussion started by: ipfreak
6 Replies

2. Homework & Coursework Questions

Question about setting up an hdd for a videoserver

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You want to set up a hard drive for a videoserver under linux. - The videofiles will have a size of at least... (1 Reply)
Discussion started by: Eggsy
1 Replies

3. UNIX for Beginners Questions & Answers

Question about setting up a hard drive for a videoserver under Linux

Hi there, I'm currently preparing for an exam and came across a question that I don't really know how to answer. "You want to set up a hard drive for a videoserver under linux. - The videofiles will have a size of at least 10MB and a maximum of 8BG. - The hard drive has a disk space of... (1 Reply)
Discussion started by: Eggsy
1 Replies

4. UNIX for Dummies Questions & Answers

Ifconfig Flags

Hi there, I need your help in understanding the below Solaris 10 ifconfig output; athnetspns02>ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 e1000g0:... (2 Replies)
Discussion started by: wthomas
2 Replies

5. UNIX for Dummies Questions & Answers

WHat are flags?

Can anybody actually tell, what is flag? I know they are termed as permission flags and various others. Please explain (3 Replies)
Discussion started by: nixhead
3 Replies

6. IP Networking

arp output (flags)

I'm running an arp -an on a Solaris 10 box. We're using IPMP. One of the systems is not able to see a host on the same network. The only difference between the two systems (one is having a problem, the other isn't) at least so far is the output of arp: # arp -an | grep 224.55 e1000g5... (1 Reply)
Discussion started by: BOFH
1 Replies

7. UNIX for Advanced & Expert Users

Processes Communication Only with flags!

hello everybody and a happy new year! i am trying the client-server model...i have no problem with sockets etc... especially for server:there is a father who is listening for TCP connections from clients,the later send commands which parent shares to his children. then children execute... (1 Reply)
Discussion started by: vaggelakis
1 Replies

8. UNIX for Dummies Questions & Answers

Basic question about setting up new users

I currently have one user (USER1) that's a member of group 'A'. I want to create a bunch of users and have them all have access to READ all of USER1's files. Should I create all of the new users and have them all be members of a new group (group 'B')?? It looks like when USER1 creates a file it... (2 Replies)
Discussion started by: FredSmith
2 Replies

9. AIX

question concerning Grep flags

Hey all. I am trying to find a process that is running and appending it to a file. The comman I am using is ps -eaf |grep tctl. The problem is, it returns the tctl process as well as the grep process that I just ran. Is there a flag that will prevent the command from returning itself? ... (2 Replies)
Discussion started by: jalge2
2 Replies

10. UNIX for Dummies Questions & Answers

if flags

Hi folks. I'm just starting to teach myself shell scripting and am having some trouble with an if statement. I am working with a directory where only one file will reside at a time and need to evaluate if this file is compressed to determine subsequent steps. I'm using echo for testing purposes.... (2 Replies)
Discussion started by: kristy
2 Replies
Login or Register to Ask a Question