Shell script to Open file in SFTP and get first 6 character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to Open file in SFTP and get first 6 character
# 1  
Old 07-13-2010
Shell script to Open file in SFTP and get first 6 character

Hi,

I am creating a script that will:
1. Connect to SFTP server
2. Get the file content's first 6 character (ddmmyy) and compare it to today's date (also in ddmmyy format). This is the header of the file. However, the header contains a few more information. So i need to only get the first 6 characters.

Below is an excerpt from my script. The <?> is where i intend to place the code to compare the 2 values. if they are equal, it will proceed to the next line .

Code:
# Generate dynamic SFTP batch file
echo "# $SFTPBATCHFILE is auto-generated" > $SFTPBATCHFILE
echo -e "\n" >> $SFTPBATCHFILE
<?>
echo "-get $SOURCEDIR/rstk.txt $TARGETDIR" >> $SFTPBATCHFILE
echo "bye" >> $SFTPBATCHFILE
 
# SFTP Development Server
sftp -b $SFTPBATCHFILE username@10.11.3.14 >> $SFTPLOGFILE

Please help. I am new in scripting.

cherriesh

Last edited by pludi; 07-13-2010 at 07:26 AM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Open and edit a file using a shell script

Hello Folks, I have a file named as date.dat present at /tmp/abc location which has following data - 20161030,20161031,20161101 I need to remove this line and replace it with something like below - $param1,$param2,$param3 Param1, Param2 and param3 stores the date based on some calculation in... (1 Reply)
Discussion started by: ektubbe
1 Replies

2. HP-UX

Shell script to sftp files to file server.

Hi, I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run. The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script. I tried with below snippet:-... (2 Replies)
Discussion started by: happysingh
2 Replies

3. Shell Programming and Scripting

To open a file in shell script.

Hi Guys, I want to open a file in shell script and copy the last file of the line for display. Can anyone help?? (3 Replies)
Discussion started by: Karthick N
3 Replies

4. Shell Programming and Scripting

Shell script to transfer file via SFTP

Hi all, I'm trying to do a script to transfer file between my server and an external server via SFTP protocol. It doesn't use rsa key, but password. When I run the script, it throw back a prompt that request me to put the password. How should I do for automatic login? Pleaes help :( ... (2 Replies)
Discussion started by: Kapom
2 Replies

5. Shell Programming and Scripting

SFTP Shell script

Hi All, I have done the Private - Public keys generation( and sharing) and have written a script for automating the SFTP. Need to make sure if it will work: sftp.sh #!/bin/bash . config.ini sftp $SFTP_USER@$SERVER <<EOF cd $SFTP_RDIR #ls -lrt | grep $SFTP_RFILE | wc -l get... (2 Replies)
Discussion started by: Arpit Narula
2 Replies

6. Shell Programming and Scripting

Open a file from within a Bourne shell Script

I am suppose to make a program that cuts the extension off of a file. It uses that .ext to decide which program needs to be used to open the file. This only finds the name of the program from a list of programs I made. My problem is when it has the name of the program it needs to use, how can I... (3 Replies)
Discussion started by: dordrix
3 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

Use cURL in shell script and get most recent file from remote server using SFTP

I have been trying to implement the following shell script -- sftp to remote server get list of files in the directory sftp get the most recent listed file exit This script will be scheduled to be executed everyday using CRON or CONTROL-M and the need is to have absolutely no human... (7 Replies)
Discussion started by: toobrown1
7 Replies

9. Shell Programming and Scripting

SFTP shell script help

HI I need to write script to transefer files from windows server to UNIX and visa versa.... can any one enroute to the solution ........? I am new to SFTP .. would requst you provide some helpful informaion, Basics of SFTP also appreciated Thanks in Advance. Madan (1 Reply)
Discussion started by: madankumar
1 Replies

10. Shell Programming and Scripting

open a file in shell script

Hi all How to open a file in a unix shell program. also i want it open for an hour and run independent of other jobs. pls help me solve this issue... (2 Replies)
Discussion started by: bankpro
2 Replies
Login or Register to Ask a Question