Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Hi, all. Let me preface this question with the acknowledgement that I am new to both shell scripting and cron, so go easy on me.
Anyway, I've got a script that I've setup to run in cron as root. What it does basically finds out what the outside IP address for my Linsys router, writes it to a text file, and FTPs it to my server at work.
When I run the script from a command propmt, it executes as it should, putting the dumpfile and the upload file in the same directory as the script in /usr/cron. But when it runs as a cron job, it makes the files in the /root directory. Being the neat-freak that I am, I wasn't happy about that, so I rewrote the script using a set path for the files to force them into the same directory. But when I run it, it returns a "permission denied" error and I can't quite figure out why.
So here's the script, which was pieced together after checking out other scripts online that do similar tasks (IPs and userinfo have been changed to protect the innocent ):
#!/bin/sh
URL='I'm apparently not allowed to post URLs untill I've got 5 posts'
DUMPFILE='ipdump.txt'
FILE='myip.txt'
HOST='xxx.xxx.xxx.xxx'
USER='xxxxxxx'
PASSWD='xxxxxxx'
lynx -dump $URL > $DUMPFILE
echo 'As of: ' > $FILE
date >> $FILE
grep -i 'your ip is' $DUMPFILE >> $FILE
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
ascii
cd xxxx/xxxx
put $FILE
quit
END_SCRIPT
exit 0
Any thoughts as to why I'm having problems specifying where the files should go? Any comments on the script? Thanks!
IMHO I'd use absoute paths. Keep in mind for the most part it's going to act as if someone is at the console typing the commands. You might want to put some 'wait' and or 'sleep' commands to help keep it under control. I do quite a bit of scripting to automate jobs such as your doing but I'm not really great at it and those commands can smooth out the rough spots of my scripting.
Originally posted by homestead1000 IMHO I'd use absoute paths. Keep in mind for the most part it's going to act as if someone is at the console typing the commands. You might want to put some 'wait' and or 'sleep' commands to help keep it under control. I do quite a bit of scripting to automate jobs such as your doing but I'm not really great at it and those commands can smooth out the rough spots of my scripting.
try:
/usr/local/test/
instead of:
test/
Ed
Using absolute paths was my first thought to control the dumpfiles, but that's when when the "permission denied" weirdness started. I didn't chmod the files or the directories, but by default the files were 755 and owned by root, so I'm wondering if that's really the issue.
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Rep:
Could you please explain the variable assignments in your script. This is a really cool idea if I understand it correctly. This script gets your dynamic ip and forwards it to you at work so you can connect from work to home? If so, please clarify the variables and basically what goes where, because I am positive others will want to try this. I sure do...
Originally posted by Pcghost Could you please explain the variable assignments in your script. This is a really cool idea if I understand it correctly. This script gets your dynamic ip and forwards it to you at work so you can connect from work to home? If so, please clarify the variables and basically what goes where, because I am positive others will want to try this. I sure do...
Thanks :-)
The variables are there just so I can keep all the things that might change in a nice convenient spot. All it does is query www_dot_whatismyip_dot_com (I'm still not allowed to post URLs due to low post-count ) Lynx captures the page, dumps it to a file, grep pulls the info I need out of the file, then it's time-stamped and copied to my FTP server. Then I set cron to send it to me twice a day.
And it's my first real script, too!
This is the end product that gets mailed to me:
As of:
Mon Jul 28 17:00:17 PDT 2003
Your IP is xxx.xxx.xxx.xxx
Originally posted by stickman You could try something like "cd /tmp" at the beginning of the script. cron should be able to write to /tmp without any problems.
That did the trick. Thanks!
Continuing with the weirdness though, the end result is the same, my IP gets FTPed to me properly, but when I check out the files that the script writes in /tmp there's nothing inside. Spooky!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.