strange behaviour script terminate before complete execution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strange behaviour script terminate before complete execution
# 1  
Old 04-24-2011
strange behaviour script terminate before complete execution

I'm working on a script to make backup of various folder located on various host using different OS.
I got a strange behaviour because the script donět process all lines of a configuration file, the script execute only one loop even the input file have 6 lines:

This is the script:
Code:
#!/bin/bash
cat file_test | while read line; do

echo "test"
ssh root@host2 'df -h'

done


Using this configuration file (file_test):
Code:
asd
asd
asd
asd
asd
asd

the logfile:
Code:
test
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             455G  4.1G  428G   1% /
none                  3.9G  280K  3.9G   1% /dev
none                  4.0G  164K  4.0G   1% /dev/shm
none                  4.0G  896K  4.0G   1% /var/run
none                  4.0G     0  4.0G   0% /var/lock
none                  4.0G     0  4.0G   0% /lib/init/rw
/dev/sdb1             1.4T  259G  1.1T  19% /data
/dev/sdd1             699G  221G  479G  32% /mnt/ext

---------- Post updated at 01:24 PM ---------- Previous update was at 12:46 PM ----------

problem is this line, probably launching a script on the remote server cause an exit message that create the error on the script
Code:
ssh root@host2 'df -h'

commenting that line all loops correctly.
Anyone can explain how call the remote script without this problem?

---------- Post updated at 03:09 PM ---------- Previous update was at 01:24 PM ----------

Solved! I've just discovered -n option of ssh

Last edited by |UVI|; 04-24-2011 at 04:28 PM.. Reason: simplify the question
# 2  
Old 04-24-2011
You've got a useless use of cat in there.

Many servers won't let you ssh into root, at all.

I don't understand why you're ssh-ing to the same host to run df for each and every line. Could you tell us your goal with this script?
# 3  
Old 04-25-2011
The script is only for example.

I've to backup various folder for various hosts, and some folder include running Virtual Machines.

So I've to launch a script on remote machine that check if there are running VM and if yes, suspend the VM, make backup with rsync, and restart the VM

The previous script is only an example to understand how call remote script in a while loop.
# 4  
Old 04-25-2011
Not sure, but try
Code:
#!/bin/bash
while read line; do
echo "test"
ssh root@host2 'df -h'
done << file_test

# 5  
Old 04-25-2011
Quote:
Originally Posted by |UVI|
The script is only for example.
If the script you're posting isn't the script you're running, it's hard to tell what's wrong with it.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange Script behaviour with Grep

Here is my script LOGDATE=`date '+%Y-%m-%d %k:%M' | cut -c1-15` echo $LOGDATE echo "grep '$LOGDATE' /tmp/logs/vel.log >10min_log" grep '$LOGDATE' /tmp/logs/vel.log>10min_log grep '$LOGDATE' /tmp/logs/vel.logHere is the output of the script -rw-r--r-- 1 wluser wluser 0 May 3... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Strange RegExp Behaviour

Hello, I was trying to identify lines who has a word of the following pattern "xyyx" (where x, and ys are different characters). I was trying the following grep - egrep '(\S)()\2\1' This pattern do catches the wanted pattern, but it also catches "GGGG" or "CCCC" patterns. I was trying to... (5 Replies)
Discussion started by: itskov
5 Replies

3. Shell Programming and Scripting

Expect script strange behaviour

Hi people, I'm having some strange behaviour with an 'expect' script. spawn csession blah expect "Username: " send "userblah\r" expect "Password: " send "passwordblah\r" interact When I execute the script as root it runs perfectly. However, when executed as any other... (0 Replies)
Discussion started by: GarciasMuffin
0 Replies

4. Shell Programming and Scripting

strange behaviour from sed???

Hi all, I want to do a very simple thing with sed. I want to print out the line number of a disk I have defined in /etc/exports, so I do: It's all good, but here's the problem. When I define md0 in a variable, I get nothing from sed: Why is that? can anybody please help? Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

5. UNIX for Dummies Questions & Answers

Strange Program behaviour

Had a strange thing going on with my code. It's ok I figured it out for myself.... (2 Replies)
Discussion started by: mrpugster
2 Replies

6. Shell Programming and Scripting

Strange behaviour from script in crontab

Apologies if this has been mentioned elsewhere, my search skills may be lacking somewhat today. I have a script that does the following (as a test): find . -name "*.txt" -exec file {} \; >>$sFullFilePath Now, the variable is set up up correctly in the script too. When I run the script... (1 Reply)
Discussion started by: PilotGoose
1 Replies

7. UNIX for Advanced & Expert Users

Strange sed behaviour

$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| $ Is the behavior of the sed statement expected ? Or is this a bug in sed ? OS details Linux 2.6.9-55.0.0.0.2.ELsmp #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux (8 Replies)
Discussion started by: vino
8 Replies

8. Shell Programming and Scripting

A Strange Behaviour!!!

Can some-one give me a view to this : I have a directory in an unix server, having permissions r-xr-xr-x .This directory is basically a source directory. Now there is another directory basically the destination directory which has all the permissions. Note:I log in as not the owner,but user... (5 Replies)
Discussion started by: navojit dutta
5 Replies

9. Linux

/etc/passwd strange behaviour!

Hi there, first of all, here is my conf of a uname -a Linux SAMBA 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown on a fedora machine. Here is my problem: every once in a while, the line containing root disappears in the /etc/passwd, disabling all logging on my server. Any one have... (0 Replies)
Discussion started by: penguin-friend
0 Replies
Login or Register to Ask a Question