[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
# 8  
Old 01-30-2013
Are you only trying to make an archive to save?
# 9  
Old 01-30-2013
Quote:
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
This is how to make your life more complicated and less reliable...
You did not answer my previous question...
# 10  
Old 01-30-2013
Since you are silent and after I will not have the time to explain anymore so look at the following command I just typed for you and meditate: It keeps the perms, timestamps etc....
Code:
ant:/home/vbe/admin/shell/tests $ ll
total 30
-rw-rw-r--   1 vbe        bin            137 Jan 30 17:17 infile
-rw-rw-r--   1 vbe        bin          14336 Jan 30 17:20 titi
ant:/home/vbe/admin/shell/tests $ more infile         
./etc/passwd
./etc/shadow
./etc/group
./etc/vfstab
./etc/profile
./etc/default/cron
./etc/default/fs
./etc/shells
./etc/default/security
ant:/home/vbe/admin/shell/tests $ cd /
ant:/ $ cpio -ocv </home/vbe/admin/shell/tests/infile >/home/vbe/admin/shell/tests/titi
etc/passwd
etc/shadow
etc/group
"etc/vfstab": No such file or directory
Cannot stat <etc/vfstab>.
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/ $ cd ~/admin/shell/tests
ant:/home/vbe/admin/shell/tests $ ll
total 30
-rw-rw-r--   1 vbe        bin            137 Jan 30 17:17 infile
-rw-rw-r--   1 vbe        bin          14336 Jan 30 17:31 titi
ant:/home/vbe/admin/shell/tests $ cpio -cit <titi                                        
etc/passwd
etc/shadow
etc/group
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/home/vbe/admin/shell/tests $ cpio -icdmv < titi                                     
etc/passwd
etc/shadow
etc/group
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/home/vbe/admin/shell/tests $ ll
total 32
drwxr-xr-x   3 root       sys           1024 Jan 30 17:33 etc
-rw-rw-r--   1 vbe        bin            137 Jan 30 17:17 infile
-rw-rw-r--   1 vbe        bin          14336 Jan 30 17:31 titi
ant:/home/vbe/admin/shell/tests $ cd etc
ant:/home/vbe/admin/shell/tests/etc $ ll
total 28
drwxr-xr-x   2 root       root            96 Jan 30 17:33 default
-r--rw-r--   1 bin        bin           4509 Jul  8  2011 group
-r--r--r--   1 root       sys           2775 Jun 23  2011 passwd
-r--r--r--   1 bin        bin           2871 Jun  2  2009 profile
-r--------   1 root       sys           1585 Jun 23  2011 shadow
-rw-rw-r--   1 root       bin            159 Sep  2  2008 shells
ant:/home/vbe/admin/shell/tests/etc $ cd default
ant:/home/vbe/admin/shell/tests/etc/default $ ll
total 8
-r--r--r--   1 root       root          1120 Aug 24  2006 cron
-r--r--r--   1 bin        bin             11 Nov 15  2000 fs
-rw-r-----   1 root       bin            232 May  7  2010 security
ant:/home/vbe/admin/shell/tests/etc/default $

the commands were passed with a sudo root...
As you can see I created an archive named titi using a file called infile...

Its a HP-UX 11.11 box, using ksh...
# 11  
Old 01-30-2013
HI Vbe,

what is this all I hardly understand anything..

---------- Post updated 01-31-13 at 01:56 AM ---------- Previous update was 01-30-13 at 11:46 PM ----------

how to tar shadow file which has r-- --- --- permission ?
It shows permission denied as below..
Code:
a dfstab 1K
a group 1K
a init 1K
a passwd 4K
a profile 2K
tar: shadow: Permission denied
a sharetab 0K
a shells 1K
a vfstab 2K

---------- Post updated at 02:26 AM ---------- Previous update was at 01:56 AM ----------

Hey it is simple:

I wrote two lines before while loop for shadow file;
Code:
sudo cp /etc/shadow /users/jack/shadow
sudo chmod  755  /users/jack/shadow

it worked well.

But why it shows this don't know but copy works well.
Code:
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] [-@] f1 f2
       cp [-f] [-i] [-p] [-@] f1 ... fn d1
       cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn


Last edited by Franklin52; 01-31-2013 at 03:51 AM.. Reason: Please use code tags for data and code samples
# 12  
Old 01-31-2013
Well if you looked at what I did:
1) Preamble you have to be root somehow ( I used sudo...)
2) To not mix the files, you keep the file structure ( tree...)
3) I did all you wanted with one command : cpio
a - It can create an archive: titi
b - Using correct options it keeps all you need to be a true archive: ownership, perms, timestamps...
c - you can see the content
d - you can restore its content
So start by reading the man pages of cpio and look carefully what I produced

UNIX has to be seen as a great toolbox, with so many tools... why try to invent new ones when one existing does the job?

--- Addendum---
Thread closed for the initial question/issues has been solved, and the topic changed...

Last edited by vbe; 01-31-2013 at 09:01 AM.. Reason: Addendum
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