Auto Ftp pseudo random file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto Ftp pseudo random file
# 1  
Old 01-28-2011
Auto Ftp pseudo random file

I have a script that generates a file which is my own incarnation of a date using the 'date' function (we'll call this script a). I would like that script to invoke my other script (script b) which contains my ftp info. Since I have yet to figure out a good way to use regular ftp (yes i can only use ftp on this box, i'll explain if needed) and not have my password be in plaintext in the file. Script a creates,
Code:
"date +%m%d%Y".tar.gz

with no problem. I need to ftp that file using script b. At the end of a i have
Code:
 ftp -n < scriptB

. Inside of script b i need it to ftp the gzipped tarball a made. One caveat, I use a variable $bkDir to create the tarball
Code:
bkDir="$frDir""date +%m%d%Y"

If I could get script b to recognize bkDir for my put command that'd be awesome. Thanks
# 2  
Old 01-28-2011
This approach is not easy but not impossible. It is a perfectly acceptable technique to avoid placing the username and password on the command line and thereby making the password visible with "ps".

Understanding your posted script has proved difficult because it never executes the date command. What follows is best guess and untested.

We must assume that you understand ftp and that scriptB only contains ftp commands. You need to create a prototype version of scriptB - say scriptB.skel
Wherever you have a variable in a ftp command, place a unique string.
e.g.
Code:
cd BACKUPDIR
put FILENAME

Note that this is not $BACKUPDIR and $FILENAME. This is a textual command file to "ftp" and has nothing to do with Shell.

Then in the calling shell script edit scriptB.skel with "sed" to change the variables to the current values.

Code:
mydate="`date +%m%d%y`"
filename="${mydate}.tar.gz"
frDir="whatever"
bkDir="${frDir}${mydate}"

cat scriptB.skel | sed -e "s/FILENAME/${filename}/g" | sed -e "s/BACKUPDIR/${bkDir}/g" > scriptB

And finally having prepared the commands:
Code:
ftp -n < scriptB


Last edited by methyl; 01-28-2011 at 04:14 PM.. Reason: and finally ... and horrendous mispost!
# 3  
Old 01-28-2011
sorry forgot my backticks on the date command, it executes the date command in my script. I just forgot them here. It was 4am my time and I was getting very sleepy.
# 4  
Old 01-28-2011
I understand.
# 5  
Old 01-28-2011
I'm going to try using arrays and obfuscated math to hide my plaintext password in my script, any thoughts or better ideas? I just want it hidden on my script. I plan on deploying it in the near future and want other users to be able to feel "safer" lol. I never use sed so a small explanation on the "s/BACKUPDIR/" parts would be nice.
# 6  
Old 01-28-2011
FTP random

ok I have one that does a ftp to different servers with different file(s).
so to start I have a driving map file with contents like:
xmlfile|server|uid|pass|remote dir|delete file before send|rename|sftp|send tofull name|zip it Y or N

Then the shell script doses some manipulations like:
[CODE]
serv_name=`echo $x |awk '{FS="|"}{print $
LUSER=`echo $x |awk '{FS="|"}{print $3}'`
pass_wd=`echo $x |awk '{FS="|"}{
for(i=1;i<=length($4);i++){
if(substr($4,i,1)=="%"){
lout=lout " "
}else{
lout=lout substr($4,i,1)
}
}
printf("%s\n",lout)}'`
[\CODE]
of course the passwords and some other areas have invalid characters like & and spaces and ! so I had to work thru those.

But the end result is I output the vars to a file(script) and then execute it and remove.
so
[CODE]
if [ "$is_sftp" = "yes" ]; then
echo "sftp $LUSER@$serv_name <<EOF" >> $ftp_fl
else
echo "ftp -n -v <<EOF" >> $ftp_fl
echo "open $serv_name" >> $ftp_fl
echo "quote USER $LUSER" >> $ftp_fl
echo "quote PASS ${pass_wd}">> $ftp_fl
fi
echo "bye" >> $ftp_fl
echo "EOF" >> $ftp_fl

ksh ./$ftp_fl >>$send_log 2>&1
[\CODE]

The file should contain all resolved parms as needed and then is cleaned up,
# 7  
Old 01-28-2011
Other posters please note that the O/P has ftp not sftp.

Quote:
I'm going to try using arrays and obfuscated math to hide my plaintext password in my script, any thoughts or better ideas?
First time you have mentioned passwords. Obviously if your ftp command file has permissions 600 this is pretty secure.

In the end there is only one answer to this. Use a ".netrc" file in the home directory of the user initiating the ftp. See "man .netrc". On most systems it will not work at all unless the permissions of the ".netrc" file are set to 600 .

Hope this helps.


Ps. The "sed" (Streams Editor) commands posted substitute "s" one string for another string. In this case we are changing a unique text string to the value of a Shell variable. The clever bit is deciding what to use for a unique string.

Last edited by methyl; 01-28-2011 at 05:55 PM.. Reason: minor grammar and Ps.
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

2. Shell Programming and Scripting

[Need HELP] Find aging file and auto FTP

Dear Experts, I have script to find aging file like this: find /ArchiveINTF/INTF name "*" -type f -mtime +365 {} \; >> agingfile.txt This script will find all files over 365 days. But, I have problem, how to auto FTP all files? Thanks Edy (3 Replies)
Discussion started by: edydsuranta
3 Replies

3. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

4. Solaris

pseudo: [ID 129642 kern.info] pseudo-device: vol0

Hi I have a system that gave me some messages on bootup that I was not used to seeing: pseudo: pseudo-device: vol0 genunix: vol0 is /pseudo/vol@0 these came with these: Feb 13 17:42:17 system1 eri: SUNW,eri0 : 100 Mbps full duplex link up Feb 13 17:42:21 system1sendmail: My unqualified... (0 Replies)
Discussion started by: mndavies
0 Replies

5. Shell Programming and Scripting

FTP random files

Hello everyone, What I'm trying to do is figure out how to ftp a set of random files each day about 50 or so maybe more or less. I have a folder on my server that gets about 1000 or so new files each day, each with today's date in the file name. We just want to take a sample each day for... (3 Replies)
Discussion started by: whegra
3 Replies

6. UNIX for Advanced & Expert Users

Count and Auto FTP

Hi, I really need to create a script that counts for file and ftp's them to a windows directory. !st problem i'm having is getting it to ftp withouty prompting me, i tried |& on the end of the ftp, but then it just hits a syntax error. 2nd problem is, i have to have a wildcard in this script. which... (3 Replies)
Discussion started by: dappa
3 Replies

7. Shell Programming and Scripting

genrating pseudo random numbers

I want to generate the file in following format -------------------------------------- mov t1, %r1 mov t2, %g1 mov t3, %o1 . . . . m times add %r1, %g1, %o1 add %r2, %g2, %o2 . . . n times ------------------------------------------- (7 Replies)
Discussion started by: hack_tom
7 Replies

8. Shell Programming and Scripting

auto ftp the files

i have writen a shell to ftp a file automatically by taking the input from a file i have created on file tstftp as set timeout 120 ftp spawn ftp expect "ftp>" send "o 11.90.2.20 \r" expect "Name:" send "itcomxxl\r" expect "Password:" send "csms091206\r" expect "ftp>" send "prompt... (1 Reply)
Discussion started by: sasiprabu
1 Replies

9. Shell Programming and Scripting

Random files do not FTP in the shell script

The following script is used to loop through files in the /tmp directory and transfer those files onto another server. However, some of the files do not transfer. It is very random when the transferring is done (i.e. one of the files won't transfer then next time, that one will transfer and... (1 Reply)
Discussion started by: RLatham20
1 Replies

10. Shell Programming and Scripting

Auto FTP to a server

Hi, I am trying to automate FTP login to a remote server and put a file there. But no matter what i do, It still is aksing me for the login and password although i have it defined in the variable. Could you tell me what is wrong with this script. I am doing this on SUN server. Pls... (11 Replies)
Discussion started by: systemali
11 Replies
Login or Register to Ask a Question