check the condition in multiple file and FTP that multiple file to server and need mail confirmation.
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
check the condition in multiple file and FTP that multiple file to server and need mail confirmation.
Hi Everyone,
I am new to Unix shell scripting.
I need FTP script to move the multiple files to server.
That file should be checked with some condition. I will describe in detail.
The file_names will be like g20180703_somecode, need to open those file and need to be checked wheather these file are having Pcode1,or Pcode2 or Pcode3 and in next line wheather it is ABC or XYZ. if these two condition are in those file. Need to FTP those file to server.
g20180703_somecode these file will be placed in x/y/z path in server.
Hi Everyone,
I am new to Unix shell scripting. I need FTP script to move the multiple files to server.
That file should be checked with some condition. I will describe in detail.
The file_names will be like g20180703_somecode, need to open those file and need to be checked wheather these file are having Pcode1,or Pcode2 or Pcode3 and in next line wheather it is ABC or XYZ. if these two condition are in those file. Need to FTP those file to server.
g20180703_somecode these file will be placed in x/y/z path in server.
Ok, so since you're new to shell scripting, this will be an *EXCELLENT* thing for you to learn with, because there are many easily-found examples, sample scripts, and tutorials on bash scripting to get you started. You can find these with a simple Google search...start there.
You also need to read the "Question Guidelines" link in my posting signature. We are happy to help you if you're stuck, but we WILL NOT write scripts for you. Doing basic research and showing your own efforts should be the first things you do.
I need FTP script to move the multiple files to server.
I second what TB0ne wrote above and add to that advice to eschew FTP. It is almost certain that you have SFTP (which is a completely different protocol/service with a similar UI) already installed and running by default. It is part of the OpenSSH server and is not only much easier to set up, can be run securely unlike FTP which can never be made even remotely secure and would be a hazard to us all if it were to be put out on the net.
That said, please show us your script (with SFTP) so we can see how far you have gotten and please say where specifically you have gotten stuck or need advice.
for i in 'cd /path'
do
dsh -n $i ls -la|grep -i ABC g201878* >>/flame/spinner/arc/temp
FILE="/x/y/z"
then
put -p $FILE or (/x/y/z)
sftp -b /x/y/z username@hostname: /z/y/x/path where to copy/
then
rm -rf /x/y/z
for i in 'cd /path'
do
dsh -n $i ls -la|grep -i ABC g201878* >>/flame/spinner/arc/temp
FILE="/x/y/z"
then
put -p $FILE or (/x/y/z)
sftp -b /x/y/z username@hostname: /z/y/x/path where to copy/
then
rm -rf /x/y/z
Use CODE tags when posting code, and as you were asked, tell us where your script is failing, and with what message(s). Using DSH for such things isn't the best approach, but if you want to feed it the result of the "ls -la...." command, you need to enclose that in backticks (to the left of the "1" on your keyboard). Also, you need to read the man page on sftp, since you can run that in batch mode to upload the files that match the pattern.
You also have a missing "if" in your "if/then" statements, the FILE variable seems to be doing nothing (since you're identifying the files in the line before that...). And since you're now using SSH/SFTP (as you should), consider using scp instead, since you could then just issue a simple one-line copy, after doing a key exchange, like:
Please remember to use [[b]code] [/code] tags around your script so that indents and other spacing is retained.
You'll also need to say clearly what you are trying to accomplish since there are no comments in your code about why you are trying specifics.
Current guess:
Code:
#!/bin/sh
set -e;
set -x;
host='IP'
user='xxxxx'
file="/x/y/g$(date +%Y%m%d%)_*"
if [ -f $file ]; then
ls -la | grep -i ABC $file >> /z/y/x';
echo "mput $file" \
| sftp -i ~/.ssh/$host.rsa -b - -l $user $host;
exit 0;
else
printf " we can't find the current data file" |mailx -s "file report"
exit 1;
fi
Again, you'll have to both work through the steps yourself as well as clarify what you are trying to accomplish. But either way, FTP is not allowed any more.
You can check your script using https://www.shellcheck.net/
As suggested you can add set -xv to help debug your script.
Your if statement as written will probably error with too many arguments due to file globing. You need to use a loop to traverse each file found in the desired directory and then check for ABC and XYZ.
As stated ftp is not recommended but the proper way to write a heredoc is
Code:
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put $FILE
quit
END_SCRIPT
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.