[Solved] Do not want to print sftp commands in log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Do not want to print sftp commands in log
# 1  
Old 06-06-2013
Question [Solved] Do not want to print sftp commands in log

Hi,

While running my ksh file, I require the logs to be written to another file. For this I use the below code:
Code:
write_log()
{
  echo `date +"%d %h, %Y %H:%M:%S"` " : " $* >> ${LOG_FILE}
}

But inside my ksh file, am connecting to sftp server and executing some commands.
So while i see the log, these commands are also getting printed. I do not want these sftp commands to get printed in the log. What should be done for that.
The log now looks like :

Code:
[06 Jun, 2013 05:39:02  :  Value of LOG_FILE : 1306060539.log
06 Jun, 2013 05:39:02  :  Job Starts
06 Jun, 2013 05:39:02  :  example.ksh
Connected to sftptest.com.
sftp> cd /test
sftp> lcd /test/files
sftp> mget *.cnm
File "/test/*.cnm" not found.
sftp> rm *.cnm
Removing /test/*.cnm
Couldn't delete file: Permission denied
sftp> quit
0
06 Jun, 2013 05:39:03  :   Download Success
06 Jun, 2013 05:39:03  :  Count of cnm files received today: 0 files
06 Jun, 2013 05:39:03  :  The files are:
06 Jun, 2013 05:39:03  : 
SFTP Process  Completed.
06 Jun, 2013 05:39:03  :  Sending mail]

Here i dont require the below commands to be printed in log.
Code:
Connected to sftptest.com.
sftp> cd /test
sftp> lcd /test/files
sftp> mget *.cnm
File "/test/*.cnm" not found.
sftp> rm *.cnm
Removing /test/*.cnm
Couldn't delete file: Permission denied
sftp> quit

Am not using any explicit commands for printing this, still it gets printed.

Last edited by Scott; 06-06-2013 at 04:09 AM.. Reason: Code tags
# 2  
Old 06-06-2013
Hello,

Could you please give me a idea which kind of operations are being performed by your script after making a sftp connection?

R. Singh
# 3  
Old 06-06-2013
Am using the below code:

Code:
sftp $USER@$HOST<<EOF 2>&1 cd $DIR
lcd $DIR/files
mget *$FILEEXT1 rm *$FILEEXT1 quit EOF


Last edited by Scott; 06-06-2013 at 04:09 AM.. Reason: Code tags
# 4  
Old 06-06-2013
Hello,

Could you please add | grep -v "sftp" into your function which is creating logs.
Here is one example for same.

eg-->
Code:
cat test | grep -v "sftp"

It will search for all sftp things and it will show only text/lines that don't have sftp init.
Please make a try to it and let me know if that helps you.


R. Singh

Last edited by Scott; 06-06-2013 at 04:10 AM.. Reason: Code tags
# 5  
Old 06-06-2013
Hi Ravinder,

I tried it out, but it delete only the rows having sftp word, but i need to delete all sftp loggings.

Here in my log the line stating "File "/test/*.cnm" not found." ,should also get deleted.

thanks
# 6  
Old 06-06-2013
reply

Hello,

Please let me know which kind of logs you are expecting in Output file. Is it Output of all the commands you are execuitng.

A example can help me a bit.



R. Singh
# 7  
Old 06-06-2013
HI,

I am explicitly logging the data which I require in the file using below method :

Code:
write_log() {   echo `date +"%d %h, %Y %H:%M:%S"` " : " $* >> ${LOG_FILE} }

So i require only those written using write_log() method. Nothing else.

This is because I need to send an email using the contents of the log file, so the log has to be user defined. But here sftp commands are getting logged, which is not required.

Last edited by Scott; 06-06-2013 at 04:51 AM.. Reason: Code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] ls -l in CentOS 6.4 after upload using sftp

Hi everyone, Something rather interesting just happened to me. I uploaded a file to a server through sftp. I closed the connection and then logged on to the server via ssh. So far so good. When I typed ls -l in the remote server to retrieve a directory listing, the file that was previously... (2 Replies)
Discussion started by: gacanepa
2 Replies

2. Shell Programming and Scripting

Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements . #!/bin/sh echo "Starting to sftp..." sftp admin@myip << END_SCRIPT cd /remotepath/ lcd /localpath/ mget myfiles*.csv bye END_SCRIPT echo "Sftp successfully." echo echo... (11 Replies)
Discussion started by: scriptscript
11 Replies

3. UNIX for Dummies Questions & Answers

Help on commands in sftp using BatchFile

Hi, The script didn't continue as "20130109" folder is already created on the destination server. Please help. Entry in script: cat > $filebatch << __EOF__ mkdir $current_date mkdir $current_date/$fpdomain cd $current_date/$fpdomain ls -l __EOF__ Error: sftp -b... (12 Replies)
Discussion started by: chococrunch6
12 Replies

4. Shell Programming and Scripting

[Solved] SFTP problem

Hi, I'm new to sh scripting and have the following problem. I have a script to sftp that is now working with ssh key. But i need to change this, i wan't to sftp with a password. I have the following script, tried a lot to make a variabel for the password. But i can't make it work ... (2 Replies)
Discussion started by: kvhindex
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] auto sftp

i was able to script: ftp -n hosname << DONE user username pwd put quite close DONE can i do same as sftp ? i tried, but it keeps asking for pwd. when i typed pwd, and it worked fine. (11 Replies)
Discussion started by: lawsongeek
11 Replies

6. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

7. UNIX for Advanced & Expert Users

[Solved] remove all print jobs from a print queue

Hello, Sometimes i need to clear all the jobs of a print queue and it is really annoying to cancel one by one. Is there a way to cancel all print jobs for a specific print queue with a single command instead of cancelling them one by one? My AIX system is 5.3 Thank you for your attention (2 Replies)
Discussion started by: omonoiatis9
2 Replies

8. Shell Programming and Scripting

commands to remote sftp

Hello, Is there a way to use wc, sed or other commands against remote sftp in a regular shell script? wc -c *.* | grep total | sed s/total// ? thanks in advance (0 Replies)
Discussion started by: chm0dvii
0 Replies

9. UNIX for Advanced & Expert Users

FTP commands in SFTP

Hi, I am in the process of migrating all my FTP data flows into SFTP to make data more secure... I have used many quote site commands in our FTP sesssion. In SFTP i found that there is no option to do such commands. Does any body here know to overcome the current situation. Regards,... (2 Replies)
Discussion started by: Astra
2 Replies

10. Shell Programming and Scripting

Need help in sftp basic commands

I'm trying to make use of some common generic functions already present in the scripts loaded in the environment. A variable VAR1 is declared and used in the generic functions. Its value is also set in the generic function. Now I need to use that generic function for PURGING of some old files... (2 Replies)
Discussion started by: livetaurean19
2 Replies
Login or Register to Ask a Question