Trigger the execution of a script on SFTP Disconnect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trigger the execution of a script on SFTP Disconnect
# 1  
Old 04-22-2016
Trigger the execution of a script on SFTP Disconnect

Hi Guys,

I suspect what I'm trying to do isn't possible, but I'm hoping someone can either confirm this or point me in the right direction.

We have a third-party application which transfers a collection of files to our SFTP server ( Ubuntu 12.04 with OpenSSH ) . Once the app disconnects, we want to trigger the running of a script to organise the files into relevant subfolders. The server is only for this application so the script can be run on every disconnect.

From what I've seen, sftp doesn't seem to have any hooks to external sources. I've looked into using inotify but I don't think this will suffice. The number of files transferred and their size will change continuously so combining inotify-on-fileclose with a timeout would be unreliable.

So my question is: Is this possible at all or am I barking up the wrong tree?

Thanks in advance.
James
# 2  
Old 04-22-2016
Well it will depend on a few things...
- Is that directory entirely dedicated to that specific application for it s dowload?
( Understand when you have moved the files found to relevant files, its can be considered as empty... and no one else but that application writes here...)
- Is the deposit RANDOM or you have a littel idea of the schedule

to start with...
# 3  
Old 04-22-2016
Set up a cron job to scan the inbound directory as frequently as nesessary. Use fuser to bypass files that are in use.
# 4  
Old 04-22-2016
@vbe

- The directory is dedicated to the sftp uploads. The script moves the files into relevant folders and then the folder is empty. There are no other apps that write to this directory.
- The deposit is controlled by a user. They press a deploy button and the content is dumped into our server. so, logically we know roughly when it should be, but the system will not. The system is also aimed at untrained/partially-trained personnel and the fewer steps to go through, the easier it is to use.

@jgt

I thought about a cron job but if the cron job fires as the files are being uploaded, only half the files will be sorted.

Thanks for your input.

James
# 5  
Old 04-22-2016
If you have control of the sending function, send two files. First the data file and secondly a trigger file. Have the cron job only orocess data files for which there is a corresponding trigger file.
This User Gave Thanks to jgt For This Post:
# 6  
Old 04-22-2016
Yep, I think that's possibly my best option (or do it with cron/manually). We don't have control of the app but we are in communication with the developers so they may be able to accommodate.

Thanks for your input.
# 7  
Old 04-22-2016
You might want to watch the sftp-server process - once it disappears from the ps listing, the script can be run. Or you could look into /var/log/auth.log:
Code:
Apr 22 16:21:46 RFreeBSD sshd[1195]: subsystem request for sftp by user RUDIC
Apr 22 16:23:27 RFreeBSD sshd[1195]: Received disconnect from 10.1.1.1: 11: disconnected by user

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trigger script based on condition

Hi Guys, I am having below code which runs based on condition, Is it possible to check condition at the time of trigger code=$1 if ;then nohup sh script.sh $val 1 & fi I need to trigger if the $code = JP then only to trigger nohup sh script.sh $val 1 & My try but wanted... (4 Replies)
Discussion started by: Master_Mind
4 Replies

2. Shell Programming and Scripting

To trigger script on particular instance

Hi Guys, I have a main_script.sh which runs every day and scheduled in crontab. in the main script i read data from config file test.config apple mango orange main_script.sh for i in `cat test.config` do if then echo 'Apple' (3 Replies)
Discussion started by: Master_Mind
3 Replies

3. Shell Programming and Scripting

Automatic script trigger

Hi, I'm looking for a way to solve the following scenario: A shell should automatically trigger / run when a text file is placed or present at a specific location. My idea - to create a cron / anacron for every minute and inside that i will call a temp script. Temp script will move to my... (9 Replies)
Discussion started by: Gautham
9 Replies

4. Shell Programming and Scripting

Connect once db disconnect after all execution

Hi All, Please see the below code. it is working fine when in 'test_file' have only one emplid. test_file contains only emplid and date, like below ... 0000221|1/12/2003 0000223|1/1/1996 Problem :- when test_file contains more then one records(emplids) it is not giving any errors... (3 Replies)
Discussion started by: krupasindhu18
3 Replies

5. UNIX for Dummies Questions & Answers

How to disconnect telnet prompt with port no in script.

Hi Gurus, I am trying to write a script for checking the status of linux servers by connecting via telnet with port no but to terminate i have to manually type "quit" .how can i terminate the telnet session in script itself.For E.g ========================================= telnet ipaddress... (3 Replies)
Discussion started by: kapil514
3 Replies

6. UNIX for Dummies Questions & Answers

Trigger execution of commands whenever number of file descriptors changes

Hi, I am a Unix Newbie :D. I want to write a program such a way that: Whenever number of filedescriptors opened by a process change, it should execute some commands (eg: write total number of FDs at that point of time to a file). I dont want to poll '/proc/<pid>/fd' at regular intervals... (3 Replies)
Discussion started by: poweruser
3 Replies

7. Shell Programming and Scripting

vpn connect/disconnect shell script

Hi I am not so good in scripting..trying ot learn it...need guidance of the experts in shell scripting.. Let me explain the scenario first.. a server MX1 is connected to another server MX2 through vpn..every 5 minute a script runs to test vpn connectivity between the 2 servers.when the vpn... (12 Replies)
Discussion started by: renuka
12 Replies

8. UNIX for Dummies Questions & Answers

Can we trigger an shell script on an event

Hi, My program A updates a log called logA. I have a shell script S that is responsible to send emails reading from the log. I want to trigger execution of the script whenever there is an update to the log. Thanks in advance. (8 Replies)
Discussion started by: cv_pan
8 Replies

9. Shell Programming and Scripting

Check if trigger Script is running

HI, I have a script which will be running all the time...it is like a trigger.. wakesup every 10 minutes(trigger.sh) executes, and I want to write another script which monitors this script every one hour and if it finds that trigger script is not running it should start it and exit...and here... (9 Replies)
Discussion started by: mgirinath
9 Replies

10. Shell Programming and Scripting

Shell script call from a DB trigger

Has anybody been able to execute a shell script call from a database trigger? If so what are the steps to execute it? Do we have any specific packages in Oracle? Reards, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies
Login or Register to Ask a Question