Sponsored Content
Top Forums Shell Programming and Scripting Need File arrival time(sftp) command Post 302570451 by michaelrozar17 on Thursday 3rd of November 2011 10:30:55 AM
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:
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
HOME(8) 						      System Manager's Manual							   HOME(8)

NAME
home, 40meg, 80meg, personalize, update, Disclabel - administration for local file systems SYNOPSIS
gnot/home gnot/personalize gnot/update magnum/home magnum/personalize magnum/update pc/40meg pc/80meg pc/personalize pc/update nextstation/home nextstation/update DESCRIPTION
These programs help maintain a file system on a local disk for a private machine. Home partitions a disk, copies the appropriate kernel to the disk, and makes a new file system on the disk. To do this, it overwrites the vendor-supplied software on the disk with a copy of Plan 9. 40meg, 80meg, and 100meg configure disks and make file systems for disks of the appropriate size. Update copies the current kernel to the disk and updates files on the local file system. It only updates those files put there by the home program. Personalize removes the contents of the /usr directory on the local disk and copies a minimal set of files for the user who runs the com- mand. The file /rc/bin/nextstation/Disclabel, despite its name, is not an rc(1) script. It contains the second stage bootstrap program for Nextstations booting from local disk. Before booting a Plan 9 Nextstation from disk, it should be installed in the partition /dev/hd1label; this is normally done by nexstation/home. FILES
/lib/proto/portproto Mkfs prototype files for magnum/home, magnum/update, gnot/home, and gnot/update. /lib/proto/386proto Mkfs prototype files for pc/40meg, pc/80meg, and pc/update. SOURCE
/rc/bin/gnot/* /rc/bin/magnum/* /rc/bin/pc/* /rc/bin/nextstation/* SEE ALSO
kfs(4), mkfs(8), prep(8), wren(3) ``Installing the Plan 9 Distribution''. HOME(8)
All times are GMT -4. The time now is 06:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy