Shell script for capturing FTP logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for capturing FTP logs
# 1  
Old 09-06-2017
Shell script for capturing FTP logs

I have a script
Code:
#!/bin/bash
HOST=ftp.example.com
USER=ftpuser
PASSWORD=P@ssw0rd
 
ftp -inv $HOST <<EOF
user $USER $PASSWORD
cd /path/to/file
mput *.html
bye
EOF

the script executes sucessfully I need to capture the FTP logs to a logfile
should contain
Code:
FTP Login successful
...

Can you please help with this ?

Last edited by vbe; 09-06-2017 at 05:35 AM.. Reason: code tags
# 2  
Old 09-06-2017
What have you tried with redirection? I think you might get it working with something like this:-
Code:
#!/bin/bash
HOST=ftp.example.com
USER=ftpuser
PASSWORD=P@ssw0rd
logfile=/path/to/logs/filename.$$
 
ftp -inv $HOST <<EOF > $logfile
user $USER $PASSWORD
cd /path/to/file
mput *.html
bye
EOF

Using $$ in the filename appends the PID, so fairly random to avoid overwriting.
You could choose a fixed log file and append to it by using >> $logfile or you could use a date/timestamp like one of these:-
Code:
logfile="/path/to/logs/filename.$(date +%Y%m%d_%T)"             # Time stamp is YYYYMoDD_HH:Mi:SS
logfile="/path/to/logs/filename.$(date +%s)"                    # Time is in seconds from the Epoch
logfile="/path/to/logs/filename.$(date +%s.%N)"                 # Time is in nano seconds from the Epoch

Some of the date flags might be OS dependant though.


Do any of these help?
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with Capturing time from Autosys logs

Hi Guys, I'm very new to Shell scripting and have to design a code which I'm not able to find a way to. I will try to explain the aim in detail and shall be obliged if anyone could help me with the coding snippet. I have an input file who's every row has a few details about an autosys Job. I shall... (1 Reply)
Discussion started by: Crusnik02
1 Replies

2. Shell Programming and Scripting

Help in capturing Time from Autosys Logs

Hi Guys, I'm very new to Shell scripting and have to design a code which I'm not able to find a way to. I will try to explain the aim in detail and shall be obliged if anyone could help me with the coding snippet. I have an input file who's every row has a few details about an autosys Job. I shall... (0 Replies)
Discussion started by: Crusnik02
0 Replies

3. Shell Programming and Scripting

Capturing name of the user who is running a shell script

Hello All, I am writing a shell script which will run on build server where multiple users can login.These users can run this script at the same time. I want to capture the name of the user who ran the script for every instance.How can I do that ? Regards,... (1 Reply)
Discussion started by: anand.shah
1 Replies

4. Shell Programming and Scripting

Capturing the killed process logs

I have two set of questions. 1) To skip killing some process automatically. 2) To kill other process and capture their log. I have set of process, some needs to be killed gracefully and others should be skipped. Listed are the process. adm 1522... (1 Reply)
Discussion started by: murali1687
1 Replies

5. Emergency UNIX and Linux Support

Capturing console (/dev/ttyS1) logs

Hi, I have been trying to capture console logs from the init script. When the ramfs is mounted, i check if usb is connected , if conncted, i mount it and redirected the console logs like so: cat & /dev/ttyS1 >> /mnt/logs.txt I'm getting /bin/sh : /dev/ttyS1 :permission denied ... (8 Replies)
Discussion started by: xerox
8 Replies

6. Shell Programming and Scripting

Capturing FTP logs

Hi Guys, I am trying to capture the FTP Logs in a log file. I am using the below code. ftp -d -n -v $Remote_Host << EOD > $Ftp_LOG; Since iam running the script in debug mode, i am able to see that the ftp is done and the file has been transferred. But the log file does not have... (7 Replies)
Discussion started by: mac4rfree
7 Replies

7. Shell Programming and Scripting

Capturing log of a shell script

Hi, I have a script which does multiple tasks in sequence. When i execute the script, it runs and displays lot of messages for each of the steps on the console. Is there any way I can capture those messages and store it for audit purposes ? Best Regards, bornon2303 (2 Replies)
Discussion started by: bornon2303
2 Replies

8. UNIX for Dummies Questions & Answers

Capturing Input Parameters on Shell Script

i have this basic line of code that doesn't work. i simply want to get the input parameter strings but when the script is run it appears that the first parameter is assigning the value to the second parameter. #!/bin/sh pdir=`pwd` p1=$1 p2=$2 echo "directory: $pdir\n" echo "parameter... (2 Replies)
Discussion started by: wtolentino
2 Replies

9. Shell Programming and Scripting

FTP script to gather logs.

Hi, I am currently working on a FTP script which would ftp to extranet servers from intranet server and gather logs based on timestamps in archive logs and by using a wildcard character in the present logs. I have the following in place AAA="Extranet Server 1:Instance Extranet Server... (2 Replies)
Discussion started by: openspark
2 Replies

10. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies
Login or Register to Ask a Question