Sponsored Content
Top Forums Shell Programming and Scripting SFTP Shell Script Get & Delete && Upload & Delete Post 302982119 by weesiong on Saturday 24th of September 2016 07:22:05 AM
Old 09-24-2016
Most important question first: Does your script do what it is intended for? If not, post what goes wrong. If yes, here's some comments on it:

- do you really need to run it continuously, i.e. will any of the files AAA*/BBB*/CCC* be recreated periodically?
YES, customer will upload filename with AAA_%% or BBB_%%...
- while [ 1 ] works (creating an infinite loop) as would while [ 0 ]. Is that what you intended to do?
YES, I want run this as Services
- you want a download as well as an upload. In the same script? Switchable? File names changing?
Can split in 2 script
- you want "specified filenames" to be down-/uploaded. This can be easily done as lines in "here documents" are expanded by the shell. Any idea on how to supply the filenames?
It is random filename, only know the prefix name
- adding comments is good behaviour in programming, but try to be more illustrative, don't state the obvious.

---------- Post updated at 06:22 AM ---------- Previous update was at 06:16 AM ----------

After 8hours research, I've this auto download script:
Code:
#!/bin/bash
Server=".ssh/xxxxx@10.x.x.x"
Logfile="ftp_log.log"
Processed_Logfile="ftp_log.processed"
Script_Logfile="ftp_log.script"
Directory="test"
Sleep=300

# -----------------------------------------------------
# Function get and remove file from server
# -----------------------------------------------------
getdelete() {
sftp -o IdentityFile=$Server <<-EOF  >$Processed_Logfile 2>&1
cd $Directory
lcd $2
get $1
echo $(date '+%Y/%m/%d %H:%M:%S') "     downloaded     " $1
rm $1
echo $(date '+%Y/%m/%d %H:%M:%S') "     deleted        " $1
!
EOF
}

# -----------------------------------------------------
# Loop job
# -----------------------------------------------------
while [ 1 ]
do
# -----------------------------------------------------
# Connect remote server get the directory list
# Save directory list in ftp_log.temp
# -----------------------------------------------------
sftp -o IdentityFile=$Server <<-EOF >$Logfile 2>&1
cd $Directory
ls -1
!
EOF
# -----------------------------------------------------
# Process line from list
# Get and remove file from remote server
# -----------------------------------------------------

while read p; do
  if [[ $p == *txt ]]
  then
    if [[ $p == AAA* ]]; then
      getdelete $p "/home/AAA/"
    elif [[ $p == BBB* ]]; then
      getdelete $p "/home/BBB/"
    elif [[ $p == CCC* ]]; then
      getdelete $p "/home/CCC/"
    elif [[ $p == DDD* ]]; then
      getdelete $p "/home/DDD/"
    elif [[ $p == EEE* ]]; then
      getdelete $p "/home/EEE/"
    fi
  fi
done < $Logfile

  #sleep in second
  sleep $Sleep
done >> $Script_Logfile 2>&1 &

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script delete log files from folder & subfolders on space usage

Hi, I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes. I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
Discussion started by: saha
3 Replies

2. UNIX for Advanced & Expert Users

Network Shell Script & Blade Logic & Network Security

I am going to take up a position in Data & Network Security. I would need to write network shell scripts doing the following task: Going to around 2000 servers and findout which groups has access to each servers and which ids are there in each group that has access. I need to implement... (1 Reply)
Discussion started by: pinnacle
1 Replies

3. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies

4. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

5. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

6. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

7. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

8. Shell Programming and Scripting

[Solved] Get files & delete them by shell script

I want to use my script to get any file then delete it once it transfers to my side , I manage to create below script to generate "list" file which contains all file names in "10.10.1.1" then I made "a.out" file which contains the commands that I want to run it on "10.10.1.1" to get & delete the... (2 Replies)
Discussion started by: arm
2 Replies

9. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

10. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies
GIT-SHELL(1)							    Git Manual							      GIT-SHELL(1)

NAME
git-shell - Restricted login shell for Git-only SSH access SYNOPSIS
chsh -s $(command -v git-shell) <user> git clone <user>@localhost:/path/to/repo.git ssh <user>@localhost DESCRIPTION
This is a login shell for SSH accounts to provide restricted Git access. It permits execution only of server-side Git commands implementing the pull/push functionality, plus custom commands present in a subdirectory named git-shell-commands in the user's home directory. COMMANDS
git shell accepts the following commands after the -c option: git receive-pack <argument>, git upload-pack <argument>, git upload-archive <argument> Call the corresponding server-side command to support the client's git push, git fetch, or git archive --remote request. cvs server Imitate a CVS server. See git-cvsserver(1). If a ~/git-shell-commands directory is present, git shell will also handle other, custom commands by running "git-shell-commands/<command> <arguments>" from the user's home directory. INTERACTIVE USE
By default, the commands above can be executed only with the -c option; the shell is not interactive. If a ~/git-shell-commands directory is present, git shell can also be run interactively (with no arguments). If a help command is present in the git-shell-commands directory, it is run to provide the user with an overview of allowed actions. Then a "git> " prompt is presented at which one can enter any of the commands from the git-shell-commands directory, or exit to close the connection. Generally this mode is used as an administrative interface to allow users to list repositories they have access to, create, delete, or rename repositories, or change repository descriptions and permissions. If a no-interactive-login command exists, then it is run and the interactive shell is aborted. EXAMPLE
To disable interactive logins, displaying a greeting instead: $ chsh -s /usr/bin/git-shell $ mkdir $HOME/git-shell-commands $ cat >$HOME/git-shell-commands/no-interactive-login <<EOF #!/bin/sh printf '%s ' "Hi $USER! You've successfully authenticated, but I do not" printf '%s ' "provide interactive shell access." exit 128 EOF $ chmod +x $HOME/git-shell-commands/no-interactive-login To enable git-cvsserver access (which should generally have the no-interactive-login example above as a prerequisite, as creating the git-shell-commands directory allows interactive logins): $ cat >$HOME/git-shell-commands/cvs <<EOF if ! test $# = 1 && test "$1" = "server" then echo >&2 "git-cvsserver only handles "server"" exit 1 fi exec git cvsserver server EOF $ chmod +x $HOME/git-shell-commands/cvs SEE ALSO
ssh(1), git-daemon(1), contrib/git-shell-commands/README GIT
Part of the git(1) suite Git 2.17.1 10/05/2018 GIT-SHELL(1)
All times are GMT -4. The time now is 05:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy