Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
07-24-2003, 01:02 PM
|
#1
|
LQ Newbie
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7
Rep:
|
Cron Scripting Weirdness . . .
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!
|
|
|
07-24-2003, 01:08 PM
|
#2
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
Check that you chmoded the file once you rewrote it:
chown root MYSCRIPT
chmod 700 MYSCRIPT
This assumes the script will be run as root.
|
|
|
07-24-2003, 03:11 PM
|
#3
|
Senior Member
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552
Rep:
|
You could try something like "cd /tmp" at the beginning of the script. cron should be able to write to /tmp without any problems.
|
|
|
07-24-2003, 07:08 PM
|
#4
|
Member
Registered: Jul 2003
Location: San Diego, CA USA
Distribution: RH 7x,8x,9x, RHE 3, Fedora Core1
Posts: 38
Rep:
|
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
|
|
|
07-25-2003, 12:35 PM
|
#5
|
LQ Newbie
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7
Original Poster
Rep:
|
Quote:
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.
|
|
|
07-25-2003, 12:55 PM
|
#6
|
Senior Member
Registered: Feb 2003
Location: The Arctic
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...
Thanks :-)
|
|
|
07-28-2003, 06:50 PM
|
#7
|
LQ Newbie
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7
Original Poster
Rep:
|
Quote:
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
Last edited by Deeter; 07-28-2003 at 07:01 PM.
|
|
|
07-28-2003, 07:02 PM
|
#8
|
LQ Newbie
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7
Original Poster
Rep:
|
Quote:
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! 
|
|
|
All times are GMT -5. The time now is 06:13 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|