Sponsored Content
Top Forums Shell Programming and Scripting How to run a script when i'm using FTP??? Post 302617827 by ygemici on Tuesday 3rd of April 2012 06:49:13 AM
Old 04-03-2012
Quote:
Originally Posted by nikhil jain
m able to do ftp, but don't know how to run a script in the destination server???
try this (before change your values[USER AND HOST AND SSH COMMAND])
Code:
# ./justdoit ftpfile
............

Code:
# cat justdoit
#!/bin/bash
FTPUSER=test ; FTPHOST=localhost
RUSR=test ; RHOST=localhost
remove() {
rm -f $HOME/.netrc
}
[ -z "$1" ] && echo "File name is empty" && exit 1
echo -e "\n___FTP PHASE___\n"
read -s -p "Please give your '$FTPUSER''s ftp password ? " passwdx
echo "machine $FTPHOST"  >  $HOME/.netrc
echo "login $FTPUSER"        >> $HOME/.netrc
echo "password $passwdx"     >> $HOME/.netrc
echo "macdef init"          >> $HOME/.netrc
echo "bin"                  >> $HOME/.netrc
echo "put $1"            >> $HOME/.netrc
#echo "bye"                  >> $HOME/.netrc
echo ""                     >> $HOME/.netrc
chmod 600 $HOME/.netrc
ftp -i localhost &>/tmp/ftplogg & ftp_id=$!;wait $ftp_id
grep "Login incorrect" /tmp/ftplogg
if [ $? -eq 0 ] ; then
echo -e "\nYour FTP password is Incorrect!!";remove;exit 1
fi
grep "No such file" /tmp/ftplogg
if [ $? -eq 0 ] ; then
echo -e "\nFTP FileName is invalid!!";remove;exit 1
fi
echo "Your FTP command probably 'SUCCESS'fully finished"
remove
echo -e "\n___SSH PHASE___\n"
ssh -o ConnectTimeout=10 -o NumberOfPasswordPrompts=1 ${RUSR}@$RHOST echo "remove echo and Add your script"
[ $? -ne 0 ] && echo -e "\nSSH 'FAILED' CHECK YOUR PASSWORD OR SSH KEYS on '$RHOST' !!\n\
Be Sure Public Key was correctly placed in 'authorized_keys' in '$RHOST' \n\
\n== Check SSH Permissions ==\n\
=================================
$RHOST/.ssh/ --> 755
$RHOST/.ssh/authorized_keys --> 644
$RHOST/.ssh/id_dsa --> 600
$RHOST/.ssh/id_dsa.pub --> 644
$RHOST/.ssh/id_rsa --> 600
$RHOST/.ssh/id_rsa.pub --> 644
$RHOST/.ssh/known_hosts --> 644
================================= \n"\
  && exit 1
echo -e "\n\"All Operations were SUCCESSFULLY completed\"\n"

regards
ygemici
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

FTP taking ages to run.

Hi every one, We have HP UX server which normally loaded as avg load of 19-21. NOw when I try and do ftp to this server it takes ages to get the FTP prompt. I have seen this server loaded as max agv load of 35-40 tht time we never had such problems of FTP sessions. Now my new Unix admin... (1 Reply)
Discussion started by: nilesrex
1 Replies

2. UNIX for Advanced & Expert Users

script to be run after every FTP transfer

Hello everyone, we are running VSFtpd as FTP Server on Redhat AS 5. I would like to have a script to be run immediately after every FTP transfer. Is is possible (or with any other FTP Server?). I thought of writing a script to monitor if FTP transfer happening and run the required-script... (2 Replies)
Discussion started by: prvnrk
2 Replies

3. Shell Programming and Scripting

FTP run from shell script gives slow transfer rates

Hey everybody, this is my first post so be gentle. I have two Sun 5220's running Solaris 10 that are directly connected with a cross-over cable at Gig. One of these boxes is my production Oracle server which generates a 50GB dump file every evening at 10:50. The other Solaris is a devolopment... (8 Replies)
Discussion started by: Countificus
8 Replies

4. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

5. Shell Programming and Scripting

Getting script to run after ftp command

Hi I, essentially have two parts in my script. The first ftp's to server S10 and retrieves a batch of files. The second part does the crunching and arranging, They both work independently but when run all in sam script I cannoy get 2nd part to run, i.e. the cat, cut & sed. I think it may be... (10 Replies)
Discussion started by: rob171171
10 Replies

6. Windows & DOS: Issues & Discussions

to run shell script using FTP

Hi All, From FTP prompt, How to run Unix Shell scripts? Thanks in Advance, (1 Reply)
Discussion started by: HemaV
1 Replies

7. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

8. Shell Programming and Scripting

How to run a shell script on a remote host using ftp

Hi, is there a way I can run a shell script through ftp on a remote host? The remote host doesn't have ssh running so I can't use ssh. (7 Replies)
Discussion started by: mrskittles99
7 Replies

9. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies
NETRC(5)						      BSD File Formats Manual							  NETRC(5)

NAME
netrc -- user configuration for ftp SYNOPSIS
~/.netrc DESCRIPTION
This file contains configuration and autologin information for the File Transfer Protocol client ftp(1). The .netrc file contains login and initialization information used by the auto-login process. It resides in the user's home directory. The following tokens are recognized; they may be separated by spaces, tabs, or new-lines: machine name Identify a remote machine name. The auto-login process searches the .netrc file for a machine token that matches the remote machine specified on the ftp command line or as an open command argument. Once a match is made, the subsequent .netrc tokens are processed, stopping when the end of file is reached or another machine or a default token is encountered. default This is the same as machine name except that default matches any name. There can be only one default token, and it must be after all machine tokens. This is normally used as: default login anonymous password user@site thereby giving the user automatic anonymous ftp login to machines not specified in .netrc. This can be overridden by using the -n flag to disable auto-login. login name Identify a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name. password string Supply a password. If this token is present, the auto-login process will supply the specified string if the remote server requires a password as part of the login process. Note that if this token is present in the .netrc file for any user other than anonymous, ftp will abort the auto-login process if the .netrc is readable by anyone besides the user. account string Supply an additional account password. If this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password, or the auto-login process will initiate an ACCT command if it does not. macdef name Define a macro. This token functions like the ftp macdef command functions. A macro is defined with the specified name; its con- tents begin with the next .netrc line and continue until a null line (consecutive new-line characters) is encountered. If a macro named init is defined, it is automatically executed as the last step in the auto-login process. SEE ALSO
ftp(1), ftpd(8) Linux NetKit (0.17) September 23, 1997 Linux NetKit (0.17)
All times are GMT -4. The time now is 05:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy