ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I have an expect script that moves files from one server to another which works perfectly. But now i need to make a change where it goes into a directory where the date changes daily, exp: filedir.latestdate, and looks for a file whos name changes daily as well, exp: uploadfile.latestdate.
Anyone know how i can script in expect to beable to determine the latest directory and can get the latest version of a file?
I have an expect script that moves files from one server to another which works perfectly. But now i need to make a change where it goes into a directory where the date changes daily, exp: filedir.latestdate, and looks for a file whos name changes daily as well, exp: uploadfile.latestdate.
Anyone know how i can script in expect to beable to determine the latest directory and can get the latest version of a file?
I'm not at my system right now, but I believe if you look at the man page for date, there are output format options. I'd either put it in YYYYMMDD format (easy human-readable, and will make sorting files easy too). That would be good if you only had one file per day.
If you had more than one file, you could do YYYYMMDDhhmm. Assigning the date variable in your script should be easy.
So this has changed a little bit to make it easier, so i need to be able to just find the latest version of a file instead of both the directory and the file.
The file looks like this with ls:
-rw-rw-r-- 1 userid userid 1564 Oct 7 10:01 server.log.2008-10-07
So in expect how do i tell sftp to just get the latest server.log according to the date?
I don't think you can ask sftp (or any ftp) to run a remote script to find the latest file. Its not what ftp is for.
If the files are rpoduced regularly eg you expect 1 per day, then you can either:
1. keep the latest file locally (or a note somewhere) and calc the next name for sftp if you get irregularly
or
2. just calc from the current date if you sftp every day
I've used (1.) several times in the past, its more flexible & you can redo if the last one was corrupt.
Right, keeing it locally is what i want to do but i still have to copy it from the remote server so it will be local. So how do you automate that, grabbing the newest file?
So like I said, if you know the date format in the filename you just calc the (expected) date of the newest file and try to sftp it. Just keep the latest file or a note so you know next time what to expect.
Start from your current file, if any.
If you haven't got any files yet, either manually get the first one, or just pick a date in the past (as far back as you need to go) and then keep looping until you run out of files or reach today's date, whichever comes first.
If you want to calc dates purely in bash, see here
i tried to set the date variable in Expect but no go. Anyone know how to make this work in expect? This is what i have below:
set date=`date "+%Y-%m-%d"` date
spawn rsync -avz -e ssh userid@remoteserver:/tmp.$date /home/userid
On the flipside, if no one knows this answer, anyone know how i can pass the password from a shell script, no i cant generate keys to make it passwordless. Its not an option. Thanks!
I dont know what to really make of that post jilinkels, i can find links myself but those links dont even have anything to do with what i asked. So... (scratches head)
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
I didn't post to show those links, I edited and removed to content of the post. Look at the reason for editing.
I made some suggestions about how to tackle this problem using Expect. After that I did some testing and found out that both SSH and FTP send a whole lot of stray characters which makes it next to impossible for Expect to recognize a usable string.
If I had let it here it would have confused you even more.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.