neaten some simple scripts...{new to these things}

neaten some simple scripts...{new to these things}

Post by Nevy » Fri, 13 Aug 1999 04:00:00



i have 2 scripts set up to cheack for new users every so often, the
point is i want to make them into just one scipt....the contents of the
scripts are below, if anyone has any suggestions plase mail them to
me,..
script 1 -passwd

echo report login names
echo ============================
echo date +%m-%y
echo ============================
echo Name-UID-Description
echo
cut -f 1,3,5 -d: /etc/passwd | sed -e 's/:/ - /'

script 2 -passwd.renew

mv -f passwd.current passwd.prev
./passwd > passwd.current
mv passwd.added passwd.added'date +%m%y'
diff passwd.current passwd.prev > passwd.added

im using SuSE 6.1 and i guess all i really want to know is how to print
the echo's as well as the command in the first script into a file from
within the second script.......i think....any ideas about neatening it
up will also be welcome....i'm new at this

*************************************
**  "yurtta sula cihanda sula"  **
*************************************

 
 
 

neaten some simple scripts...{new to these things}

Post by Abdullah Ramazanogl » Sat, 14 Aug 1999 04:00:00


Merhaba Nevin,

Quote:> i have 2 scripts set up to cheack for new users every so often, the
> point is i want to make them into just one scipt....the contents of the
> scripts are below, if anyone has any suggestions plase mail them to
> me,..

To append script1 to the end of script2: # cat script1 >> script2

Quote:> script 1 -passwd

> echo report login names
> echo ============================
> echo date +%m-%y
  ^^^^ remove
> echo ============================
> echo Name-UID-Description
> echo
> cut -f 1,3,5 -d: /etc/passwd | sed -e 's/:/ - /'

> script 2 -passwd.renew

> mv -f passwd.current passwd.prev
> ./passwd > passwd.current

  cp -f passwd passwd.current
Quote:> mv passwd.added passwd.added'date +%m%y'

                              `date +%m%y`
But you are time-stamping previous run's output with todays date. I
would swap this line with the next one.

Quote:> diff passwd.current passwd.prev > passwd.added

> im using SuSE 6.1 and i guess all i really want to know is how to print
> the echo's as well as the command in the first script into a file from
> within the second script.......i think....any ideas about neatening it

To write a command's *standard* output to a file: # command > file
Both to console and a file: # command | tee file

To append it to the end of file: # command >> file
Both to console and file: # command | tee -a file

This is by no means exhaustive. Not every command writes to std-out.
Many writes certain parts of output to std-out, and other parts to
std-error (though it is not necessarily an "error message"). Since both
std-out and std-err are redirected to console by default, you will not
notice which is which while working at console. But when you redirect it
to a file, some parts may go to the file while others still go to
screen. To send std-err and std-out combined to a file, use 2>&1 at the
end. E.g. # command > file 2>&1
And please don't take my word without cross checking with "man bash".
Sometimes I lie :)

Quote:> up will also be welcome....i'm new at this

I would suggest reading "man bash" thoroughly is a near-must. It is long
and crammed with info. Read it slowly and don't skim: You will never
regret it.

?ak
--
Abdullah Ramazanoglu    [ aramazanoglu AT demirbank DOT com DOT tr ]

 
 
 

neaten some simple scripts...{new to these things}

Post by Nevy » Sat, 14 Aug 1999 04:00:00




> Merhaba Nevin,

> > i have 2 scripts set up to cheack for new users every so often, the
> > point is i want to make them into just one scipt....the contents of the
> > scripts are below, if anyone has any suggestions plase mail them to
> > me,..

> To append script1 to the end of script2: # cat script1 >> script2

> > script 1 -passwd

> > echo report login names
> > echo ============================
> > echo date +%m-%y
>   ^^^^ remove
> > echo ============================
> > echo Name-UID-Description
> > echo
> > cut -f 1,3,5 -d: /etc/passwd | sed -e 's/:/ - /'

> > script 2 -passwd.renew

> > mv -f passwd.current passwd.prev
> > ./passwd > passwd.current
>   cp -f passwd passwd.current
> > mv passwd.added passwd.added'date +%m%y'
>                               `date +%m%y`
> But you are time-stamping previous run's output with todays date. I
> would swap this line with the next one.
> > diff passwd.current passwd.prev > passwd.added

would i still end up with the same result if the  line that starts with
'sed' in the first scrip was at the end of the econd script.....the way i
understand it i would leave the updated list of users, ie the list as of
now,* to never get used....