[Solved] Simple script not working- for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Simple script not working- for loop
# 1  
Old 01-30-2013
RedHat [Solved] Simple script not working- for loop

Hi all,
Please guide me writing this script
Follwing is the file which I have created, which contains the files to be copied.
Code:
cat system1-dr.txt
/etc/passwd
/etc/shadow
/etc/group
/etc/vfstab
/etc/profile
/etc/default/init
/etc/shells
/etc/dfs/dfstab
/etc/dfs/sharetab
/etc/default/password

This is the small script I have written for this task , but when I execute it instead of files defined in system1-dr.txt getting copied system1-dr.txt file get copied.
below is the script
Code:
cat script1
for i in /users/jack/system1-dr.txt
do
sudo cp $i /users/jack/DRbep01
done
cd  /users/jack/DRbep01
tar-cvf system1.tar *
scp system1.tar backupserver:/users/jack/stsyem1

Could you please guide me in this and how more sophiscated script can I make it..?
# 2  
Old 01-30-2013
Use while loop instead...

Code:
 
while read i
do
sudo cp $i /users/jack/DRbep01
done</users/jack/system1-dr.txt

# 3  
Old 01-30-2013
Sorry,
Can't understand any thing from your reply.
can you explain same with my script.

Thanks,
Manali
# 4  
Old 01-30-2013
Your script should be like this..

Code:
 
$cat script1
 
while read i
do
sudo cp $i /users/jack/DRbep01
done</users/jack/system1-dr.txt
cd  /users/jack/DRbep01
tar-cvf system1.tar *
scp system1.tar backupserver:/users/jack/stsyem1

This User Gave Thanks to pamu For This Post:
# 5  
Old 01-30-2013
replace
Code:
for i in /users/jack/system1-dr.txt

with
Code:
for i in `cat /users/jack/system1-dr.txt`

the code between ` ` will be executed and become arguments for "for loop"
This User Gave Thanks to mstafreshi For This Post:
# 6  
Old 01-30-2013
Though the previous post is absolutely correct, we here at unix.com are more in favor of pamu's solution for it avoids the use of a not necessary cat command
This User Gave Thanks to vbe For This Post:
# 7  
Old 01-30-2013
HI pamu,

Thanks, your while loop works.
But could you all please tell two things

How to put command in this while loop or script which will
-rename /etc/default/passwd to passwd-default as there are two file named passwd on system and other is under /etc/passwd

-secondly this /etc/shadow file is having r-- --- --- permission so first I need to change its permission to say 755 and then copy to /users/jack/DRbep01

It will be great help to me to know this, I am beginner in scripting,I will get idea by your suggestions.

Please advise
Thanks,
Manali
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple sftp script not working - Please help

I have the below sftp script to transfer a file from a linux host(source) to another linux host(target). Public key is already set up in target host and I am able to transfer file using sftp from source to target. But not sure why the below script(ftp_script) is not working. Any help in this... (3 Replies)
Discussion started by: Armaan
3 Replies

2. Shell Programming and Scripting

[Solved] Shell script not working in crontab

Hi Iam running below script in crontab but its not working. #!/bin/sh cd /Scripts /usr/local/bin/expect -f /Scripts/bng_backup.exp /Scripts/data.txt tar -cf bngbackup.tar bngbackup ;gzip bngbackup.tar when iam running manually the output file is generating..but bngbackup.tar.gz file... (5 Replies)
Discussion started by: surender reddy
5 Replies

3. UNIX for Dummies Questions & Answers

Email Script not working when added to cron[solved]

Hi I have written an email script in python which sends email to the given id. I have customized the script for generating space alert inside a shell script as shown below df -h /microfocus > /tmp/spacereport ## Filter the %usage to variable per per=$(awk '{if (NR==3){print $4}}'... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Simple while loop does not exit

spath="/home/user/k/${1}" dpath="/home/user/seq/Nov17/${1}" cd $dpath ls -1 $spath > list c=1 while read list newlist=`echo $list | sed 's/.gz//' ` newnewlist=`echo $newlist | sed 's/.fastq//' ` do echo $c echo $list c=$(($c+1)) (6 Replies)
Discussion started by: analyst
6 Replies

5. Shell Programming and Scripting

simple script to alert if internet not working?

Hi, I am constantly automaticaly downloading a few things on the internet but since my internet connection is unstable, it sometimes wont work. Thing is the internet will appear to be connected, but no website can be accessed and no program can successfully connect to any location. I can fix... (4 Replies)
Discussion started by: fuzzylogic25
4 Replies

6. Shell Programming and Scripting

Simple LOOP script help

I am trying to create a simple ksh loop script. What I've pasted below is not working. Any help is appreciated. typeset -i count typeset -i tcount count=0 tcount=0 while $tcount >= 11 do print "\$count is $count" pwd ls -l sleep 30 $(( $tcount = $count + 1 )) ... (5 Replies)
Discussion started by: musikman65
5 Replies

7. Shell Programming and Scripting

simple cgi script not working

hi all, i have installed simple cgi-script under apache/cgi-bin directory hello.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print <<END_HTML; <html> <head></head> <body>Hello, World!</body> </html> END_HTML when i hit the url... (6 Replies)
Discussion started by: raghur77
6 Replies

8. Shell Programming and Scripting

Simple BASH script not working?

So I need a script that does the following: If a certain user is logged in Run `command` Else Echo “incorrect user” This is my first stab...which doesn't work: #!/bin/bash X="user=`ls -l /dev/console | cut -d " " -f 4`" Y="foobar" echo $X echo $Y (4 Replies)
Discussion started by: doubleminus
4 Replies

9. Shell Programming and Scripting

simple perl script not working

why won't below work? I am trying to see a)sipfile has username of the system. b)it will read the sipfile and do a grep function against the /etc/passwd c)it will save that output to /tmp/result.. but my script is just hanging... #!/usr/bin/perl -w open(SIPFILE, "</tmp/sipfile") ... (4 Replies)
Discussion started by: hankooknara
4 Replies

10. Shell Programming and Scripting

Why this simple script, is not working ?

Hi everybody I want to create 20 file using simple script - listed bellow-. But the script doesn't work. I hope anyone guide me to correct this script ---------------- The script integer number=01 until (($number==21)) do >TELE-LOG-$number number=$number+01 echo $number done exit... (4 Replies)
Discussion started by: so_friendly
4 Replies
Login or Register to Ask a Question