running a bash script even after logging out from the current session

HI ,
I have a simple script that moves files from one folder to another folder, I have already done the open-ssh server settings and the script is working fine and is able to transfer the files from one folder to another but right now I myself execute this script by using my creditianls to connect through remote server through putty ...the script is below...

#!/bin/bash
 . /home/p2000/sxs137/scripts/archieve2.config
sftp $userid@$Remoteurl <<EOF
lcd $SrcFolders
cd $DestFolder
mput $SourcefilePattern
exit
EOF


Now I want this script to be run automatically after every 1 hour ,even after I have log out from my session it should be run in background , how I would achieve that..?will nohup command will support this ..please advise me..!!

To run this job for a single time, then go with nohup command ..

$ nohup sh script_name.sh &

If you need to run this for every 1 hour, better go with cron entry ..

Hi jayan_jay,
Thanx a lot , amazing, nice explanation , one thing I want to make clear using nohup command is running a job in background continuously...? since I want my script to check at source folder then pick up the txt files from there and the text files will be generated in source folder after every 1 hour , so my above script should check the source folder after every 1 hour and from there pick p the files and put it into destion...which one will be better choice ...please guide...?
and one thing more is that this service should continue to run even after i come out from my current session that is in the backgroud it should continue to run..!!

For your above scenario, go with cron entry ..

Guide: Crontab � Quick Reference

1 Like

Hi ,
Can you please guide me for corntab entry ...how it would be if I want my SFTP script should run every day, after 1 hour ....and even I log out from my session..!!Thanks in advance