1832833 Members
2979 Online
110047 Solutions
New Discussion

Re: shell for audit

 
SOLVED
Go to solution
Victor_5
Trusted Contributor

shell for audit

I am writing a shell for monthly audit, here is the requirement:

1. start up ftp and connect to server myprod
2. change directory to /etc
3. from within this directory pull the passwd file to my desktip and rename it to passwd_myprod.txt
4. open the file and convert the format as the attached file

I know sed or awk can do this kind of thing, but step by step shell would be really appreciate.

6 REPLIES 6
Bernie Vande Griend
Respected Contributor
Solution

Re: shell for audit

To convert the file, just use the following awk command:

cat passwd_myprod.txt | awk -F: '{print $1"\t"$3"\t"$4"\t"$5"\t"$6}' > newfilename.txt

Ye who thinks he has a lot to say, probably shouldn't.
harry d brown jr
Honored Contributor

Re: shell for audit

Try this for a jump start:


cat /etc/passwd | awk '{split($1,arr,":")
printf("%8s %8d %8d %20s %40s\n",arr[1], arr[3], arr[4], arr[5], arr[6])
}'
Live Free or Die
Sachin Patel
Honored Contributor

Re: shell for audit

Hi Shawn

Try this.
ftp -n IP <<-EndFTP
user user_name user_password
ascii
cd /etc
get passwd
bye
EnfFTP
Then as bernie says use awk.

Sachin

Is photography a hobby or another way to spend $
Victor_5
Trusted Contributor

Re: shell for audit

Hi Sachin:

Thanks for your message.

However, I may ftp from anywhere, for instance, I may ftp from A to unix box, and I want to copy the file to B, not A, how to do so?
harry d brown jr
Honored Contributor

Re: shell for audit


In ftp:

get currentfilename newfilename
Live Free or Die
Bernie Vande Griend
Respected Contributor

Re: shell for audit

Shawn,
Are you saying you want to ftp from machine1 to machine2 and place the file on machine3?
You can't do that unless you use 2 ftp sessions. One to get it from machine2 to machine1 and then another to put it on machine3.

Secure shell's scp can do this however:
Example, as if issued from machine1.
(This assumes the user on machine1's public key is on both of the other machines.)
scp username@machine2:/etc/password username@machine3:/etc/password.machine2
Ye who thinks he has a lot to say, probably shouldn't.