Need File arrival time(sftp) command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need File arrival time(sftp) command
# 1  
Old 11-02-2011
Need File arrival time(sftp) command

Hi All,

I am getting some file through using sftp from another server to my server.

I want know the exact file arrival time on my sytem

I have tried stat command . it gives me the below details

Code:
[user01]$ stat abc.txt
  File: `abc.txt  Size: 24231           Blocks: 48         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 542207      Links: 1
Access: (0660/-rw-rw----)  Uid: (  501/  user01)   Gid: (  501/  user01)
Access: 2011-11-02 09:20:01.630906651 +0000
Modify: 2011-11-02 09:14:45.836007547 +0000
Change: 2011-11-02 13:10:01.091905113 +0000


here access, modify and change time does not show the exact file arriavel time. it changaes if we move or edit the file.


so i want to know the exact command for file arrival.

Please help me to do so

Thanks
# 2  
Old 11-02-2011
Not possible, the create date/time isn't stored anywhere in UNIX.
# 3  
Old 11-02-2011
This works if you're using OpenSSH. Edit the /etc/ssh/sshd_config file and change the following entry:

From:
Code:
Subsystem sftp /usr/libexec/openssh/sftp-server

To:
Code:
Subsystem sftp /usr/libexec/openssh/sftp-server -l INFO

Restart the sshd daemon.

Now all transfers will be logged to your syslog:
Code:
Nov  2 09:24:00 someserver sftp-server[5577]: session opened for local user root from [192.168.1.x]
Nov  2 09:24:11 someserver sftp-server[5577]: open "/tmp/testmefile" flags WRITE,CREATE,TRUNCATE mode 0644
Nov  2 09:24:11 someserver sftp-server[5577]: close "/tmp/testmefile" bytes read 0 written 0
Nov  2 09:24:13 someserver sftp-server[5577]: session closed for local user root from [192.168.1.x]

Hope this helps.

Last edited by zaxxon; 11-02-2011 at 10:39 AM.. Reason: code tags, see PM
# 4  
Old 11-03-2011
HI in2nix4life,


Thanks for the help but i dont have acces to open sshd_config :-(

Is their any other option ,i must need to know the command??


Thanks

Last edited by aish11; 11-03-2011 at 06:21 AM..
# 5  
Old 11-03-2011
If you have no access it because you are not root... and trust Franklin, there is no other command... It up to you to find a workaround like appending timestamp to the file or creating a timestamp file to use to compare
# 6  
Old 11-03-2011
I was trying a script for your requirement. IMO this script needs to be run every 5 mins to cache the files once it arrived.

1. Get the initial count of files arrived. Run this command only once.
Code:
ls -l /ftp/home/ |wc -l >/home/scripts/prev_count.txt

2. Use the below script to store the files as and when arrived thru ftp (however it runs thru cron for every 5 mins )
Code:
#!/bin/ksh
# Assume this script is placed at /home/scripts/ and ftp files arrive at /ftp/home/
# save the script as get_arrival_file.ksh

PRE_COUNT=$(cat /home/scripts/prev_count.txt) # store the prev_count.txt, which was got in step 1, to a variable
CUR_COUNT=$(ls -l /ftp/home/ | wc -l) # Get the current total count of files arrived

# if the current count is greater the previous count then we have got new files arrived
if [[ $CUR_COUNT -gt $PRE_COUNT ]]
then
        echo "New files arrived: $(date)"
        DIFF=$(($CUR_COUNT - $PRE_COUNT)) # take the difference b/w previous count and current file count
        ls -lt /ftp/home > /home/scripts/cur_file_list.txt # send the current list of files to a .txt file
        awk -v c="$DIFF" 'NR>1 && NR<=c+1 {print $0}' cur_file_list.txt >> /home/scripts/arrival_time_list.txt # based on the diff get the new files arrived to a file
        echo $CUR_COUNT > /home/scripts/prev_count.txt # store the current file count to prev_count.txt
else
        echo "No change in files"
fi

3. Cron entry to run every 5 mins.
Code:
*/5 * * * * /home/scripts/get_arrival_file.ksh >>/home/scripts/get_file_cron.txt

This User Gave Thanks to michaelrozar17 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sftp file creation time

Hi Team, Could you please let me know ,how to find the file creation date time in SFTP server. i tred like , ls -ltr command only availble and not available like ls --full-time test.txt please help? Thanks (7 Replies)
Discussion started by: bmk123
7 Replies

2. Shell Programming and Scripting

Sftp file creation date and time

Hi Team, How to get the file creation date and time in SFTP server we can able to type ls -ltr command only SFTP server. Generally we type ls --full-time test.txt we will get the date and time , same way how to do in SFTP server after connected. Thanks (1 Reply)
Discussion started by: bmk123
1 Replies

3. Shell Programming and Scripting

Write log file for SFTP command

Hi I am transferring files to SFTP Server using sftp command(below), and want to write log file of this activity. Can you please advise if i am doing wrong. sftp -v -oIdentityFile=/home/bbm_user/bbm/private_open_ssh.ppm umf-sftp@bbm-prod-send.com <<EOF put $local_path/*.gz $remote_path/... (3 Replies)
Discussion started by: cnrj
3 Replies

4. 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

5. Shell Programming and Scripting

shell script to get the arrival count of file

Hello All, I have come across a small problem. It would be great if any of you could help me in resolving the issue. one file named dummy.txt will be ftped to Unix machine twice daily. If i receive it second time in a day i need to do some processing with the file. How to find the... (2 Replies)
Discussion started by: RSC1985
2 Replies

6. Shell Programming and Scripting

need to invoke a script upon arrival of a file

hi all, i recieve a file from other server, on a daily basis .... but the time of arrival is unpredictable .... i need to move this file to another directory before the next file arrives ... i have written a script that does this op and performs some manipulations on the data... but i... (2 Replies)
Discussion started by: sais
2 Replies

7. UNIX for Dummies Questions & Answers

File Missing When Grabbing Files from SFTP Server using SCP Command

Hi, I have this problem where sometimes my files would go missing when I schedule my crontab to run the SCP command to get file from the SFTP server. My crontab will run the scripts at an interval of 3 minutes (between the two scripts) The following is the setting in my crontab. ... (1 Reply)
Discussion started by: gingervitus
1 Replies

8. UNIX for Advanced & Expert Users

sftp command for file transfer

hi, I need to sftp a file from one unix system to another unix system. eg: filename is test.txt servername : abc@xyz please give me the sftp command for that. thanks in advance.. mohan.p (2 Replies)
Discussion started by: mohanpadamata
2 Replies

9. Windows & DOS: Issues & Discussions

sftp not get txt file 2nd time

I use sftp batch script to copy file from a remote server to local machine. Problem is when I rerun this shell after copying txt file it do not allow me to copy txt file again. My question is , is this confrigration problem of remote server. beace same shell work fie with the other remote... (3 Replies)
Discussion started by: Jamil Qadir
3 Replies

10. Shell Programming and Scripting

File arrival status

If there is a file being transferred from one box to another box, How can one confirm on the 2nd box..that the file has arrived, and transfer is complete ? I mean in addition to checking the file exists, I want to confirm its transferred completely and not growing in size. (4 Replies)
Discussion started by: amsh76
4 Replies
Login or Register to Ask a Question