Loop Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop Shell
# 1  
Old 04-26-2013
Loop Shell

I'm new to writing Shells and I’m stuck after trying to loop my shell.
I hope someone can help me out with the loop part.

I would like my shell to work as following.
- Test network connection of mount (by locating a file on the mounted location.
- If present, sync data with mounted location.
- If not present create a mount and then restart the shell.
- After the restart the shell should proceed with the synchronizing the data and then stop the shell after its done.

Code:
#!/bin/sh
FILE=/mnt/kerio_backup/BU_Server.txt
#
#Sync local files to server
# 
#Check if the file BU_server.txt is present to see if mount with server is active
#If connection is ok, then copy files to server
#Otherwise create mount with server and then loop
#
if [ -f $FILE ];
then               #Sync data with server 
   rsync -au /media/Kerio-Data/kerio/store/archive/*.* /mnt/kerio_backup/archive/ 
else               #Mount /mnt/kerio_backup with serverlocation 
   mount -t cifs //***.***.*.*/Kerio/Backupnew /mnt/kerio_backup -o user=******,password=******
   #Start loop
fi


Last edited by vbe; 04-26-2013 at 11:06 AM.. Reason: code tags please next time for you code and data...
# 2  
Old 04-26-2013
Why not use the neg logic: If not -f... then mount
for after you can rsync in all cases...
Yoour loop is unclear to me.. what are you trying?
# 3  
Old 04-26-2013
Code:
#!/bin/sh
FILE=/mnt/kerio_backup/BU_Server.txt
#
#Sync local files to server
# 
#Check if the file BU_server.txt is present to see if mount with server is active
#If connection is ok, then copy files to server
#Otherwise create mount with server and then loop
#
iterations=0
while [ 1 -eq 1 ]; do
  iterations=`expr $iterations + 1`
  if [ $iterations -gt 2 ]; then
    Echo 'ERROR!!!'
  fi
  if [ -f $FILE ]; then
    echo Sync data with server
    rsync -au /media/Kerio-Data/kerio/store/archive/*.* /mnt/kerio_backup/archive/
    break
  else
    Echo Mount /mnt/kerio_backup with serverlocation
    mount -t cifs //***.***.*.*/Kerio/Backupnew /mnt/kerio_backup -o user=******,password=******
    continue
  fi
done

# 4  
Old 04-29-2013
Quote:
Originally Posted by vbe
Why not use the neg logic: If not -f... then mount
for after you can rsync in all cases...
Yoour loop is unclear to me.. what are you trying?
I want to use a loop, to ensure when the backup server is down the shell doesn't start copying to the local folder in mnt/
This way the local HD would get full (its just a small SSD) and cause troubles on the mailserver.

---------- Post updated at 02:40 AM ---------- Previous update was at 02:39 AM ----------

Quote:
Originally Posted by hanson44
Code:
#!/bin/sh
FILE=/mnt/kerio_backup/BU_Server.txt
#
#Sync local files to server
# 
#Check if the file BU_server.txt is present to see if mount with server is active
#If connection is ok, then copy files to server
#Otherwise create mount with server and then loop
#
iterations=0
while [ 1 -eq 1 ]; do
  iterations=`expr $iterations + 1`
  if [ $iterations -gt 2 ]; then
    Echo 'ERROR!!!'
  fi
  if [ -f $FILE ]; then
    echo Sync data with server
    rsync -au /media/Kerio-Data/kerio/store/archive/*.* /mnt/kerio_backup/archive/
    break
  else
    Echo Mount /mnt/kerio_backup with serverlocation
    mount -t cifs //***.***.*.*/Kerio/Backupnew /mnt/kerio_backup -o user=******,password=******
    continue
  fi
done

Thank you verry much!
I wil try today.

---------- Post updated at 07:06 AM ---------- Previous update was at 02:40 AM ----------

Thanx hanson44

I made a few changes (Echo >echo) to your post and now it works like i wanted.

Smilie
# 5  
Old 04-29-2013
I'm glad it's working. Sorry about the typo. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

For loop in bash shell

Hi, I am using a for loop to manipulate files data_1.txt through data_100.txt. The for-loop is set up like this: for i in {1..100}; do cut -f1 data_$i.txt > output$i.txt I get the following error message when I run the code: cannot open `data.txt' for reading: No such file or directory... (4 Replies)
Discussion started by: evelibertine
4 Replies

2. Shell Programming and Scripting

about loop in shell

Hi, morning, everyone! I want to make more than one loop in a single shell script, this is what I want to do, but it doesn't run loop2. #!/bin/bash if f in *AA* do command1 command2 done if f2 in *DD* do command1 command2 done (1 Reply)
Discussion started by: xshang
1 Replies

3. Shell Programming and Scripting

For loop like execution in shell

Hi, In the script that i work now, I wrote the script such a way that the values retrieved using a tcl script is passed into a shell script to specify the path where the specific file needs to be sourced exists. For eg: I got a path from the tcl script given below, ... (6 Replies)
Discussion started by: shivashankar_S
6 Replies

4. Shell Programming and Scripting

while loop shell scripting help

hi i was wondering if someone can help me with a while loop..i have been looking at this for hours and dont no wut to do.. i have to make a menu style.. to have a beeter understanding i have linked a photo at the bottom... http://www.mypicx.com/uploadimg/772204432_08022011_1.pngand then ... (1 Reply)
Discussion started by: beerpong1
1 Replies

5. Shell Programming and Scripting

loop problem in c shell

Hi all, i got problem with this statement. I use 2 time loop while in 1 statement . But it excetu at second loop while. I want it continue loop until it stop when wrong. Plz help me -- #!/bin/csh set app_dir = "/ebsxe/ebs25/users/mmlim/assignment01" set line_array = (`cat... (0 Replies)
Discussion started by: proghack
0 Replies

6. Shell Programming and Scripting

while loop in shell scripting

Hi, I have a doubt in usage of while loop in Shell script as Iam new to this. My requirement is that,I have two different directories containing some files which move files to other folder after parsing is done. In my script i wanted to add a while loop which checks for the count in these two... (5 Replies)
Discussion started by: jyothi_wipro
5 Replies

7. Shell Programming and Scripting

Loop in shell script

Dear experts, i am quite new to shell script please any one can help me in this regard i would like write a script which takes input in the form >./Test.sh a,10,b,20,c,30... in this way i can give input in any number which is not constant in the end through loop i want to... (3 Replies)
Discussion started by: vin_pll
3 Replies

8. Shell Programming and Scripting

Help with loop in a shell script

I just want to write a little script, that reads the lines from a file, echos somthing in a new tmp.file and then do some commands whith the tmp.files. while read -r line do echo "TEST=" > tmp.$$ echo "$line" >> tmp.$$ any_command < tmp.$$ done < $INPUTFILE But I think I have to... (2 Replies)
Discussion started by: elifchen
2 Replies

9. Shell Programming and Scripting

If then else loop in Shell script

Hi Following is the code . When I give input as Bangalore,its dospalying Welcome to Hitech City. But say , if I select Delhi or US, its not displaying the corresponding message. Its still says Welcome to Hitech City. Seems that it not entering in the elif part. Please suggest. #!... (4 Replies)
Discussion started by: pankajkrmishra
4 Replies

10. Shell Programming and Scripting

for loop problem in K shell

I want to echo from 1 to 100 using a for loop. I was trying out all possible syntax using for loop, but it errors out. can you help me in doing this? I was using for i in 1..100 do echo $i done Regards Asutoshch (4 Replies)
Discussion started by: asutoshch
4 Replies
Login or Register to Ask a Question