Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I need to copy every hour some files from local directory to remote vis sftp.
I open 1 session for all files and copy them to remote host with mput.
But if the copying would be wrong - for example connection would be lost. How I can know abouit it in the Bash.
First, in timed things like this, you might consider building this as a cron job. It can make the script less complex and gets rid of the need of another programming running all of the time.
Now then, to answer your actual question. After:
sftp -b /dev/fd/0 $TARGET_USER@$TARGET_HOST>>$FTPLOG 2>&1<<EOT
try checking the exit status of sftp. Like:
Code:
RET=$?
if [ $RET -eq 0 ]
then
it worked
else
it didn't
fi
"$?" is the return code for the previously executed process. Usually, if it's zero, everything is fine.
First, in timed things like this, you might consider building this as a cron job. It can make the script less complex and gets rid of the need of another programming running all of the time.
Now then, to answer your actual question. After:
sftp -b /dev/fd/0 $TARGET_USER@$TARGET_HOST>>$FTPLOG 2>&1<<EOT
try checking the exit status of sftp. Like:
Code:
RET=$?
if [ $RET -eq 0 ]
then
it worked
else
it didn't
fi
"$?" is the return code for the previously executed process. Usually, if it's zero, everything is fine.
Yes, it may be use when the connection will fail, but if while during
sftp session working on remote computer and there script could'nt copy some files or some permissions incorrect. And that its why sftp will give
Code:
RET=$?
TRUE but files didn't copy to remote host. How I can see that all files copyed successfully?
Then you can't do it... in SFTP
Look, you can either send & chmod all the files in one go, then use an ssh session to do a remote 'ls -l' (assuming you can ssh in), or you check each operation as you go.
Your choice.
Another way that might do what you want with one session would be to use one of the Perl SSH modules. I think you'd be able to do an scp within the ssh session, as well as the chmod cmd, and check as you go.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.