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. |
Quote:
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. |
Quote:
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 |
Quote:
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: Code:
scp user@remote.host:/x/y/z/g2018* /some/local/path |
I have modified the code. Could everyone please check and advice me.
#!/usr/bin/ksh HOST='IP' USER='xxxxx' PASSWD='0000' FILE="/x/y/g$(date +%Y%m%d%)_*" if [ -f $FILE ] ; then ls -la |grep -i ABC $FILE >> /z/y/x ftp -v -n $HOST >>END_SCRIPT quote USER $USER quote PASS $PASSWD mput $FILE quit END_SCRIPT exit 0 else printf " we can't find the current data file" #|mailx -s "file report" fi Output: i am getting we can't find the current data file. I have not checked the condition Pcode1,Pcode2,Pcode3.Please do the needful |
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 |
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 |
All times are GMT -5. The time now is 10:18 AM. |