LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 07-24-2003, 01:02 PM   #1
Deeter
LQ Newbie
 
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7

Rep: Reputation: 0
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!
 
Old 07-24-2003, 01:08 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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.
 
Old 07-24-2003, 03:11 PM   #3
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
You could try something like "cd /tmp" at the beginning of the script. cron should be able to write to /tmp without any problems.
 
Old 07-24-2003, 07:08 PM   #4
homestead1000
Member
 
Registered: Jul 2003
Location: San Diego, CA USA
Distribution: RH 7x,8x,9x, RHE 3, Fedora Core1
Posts: 38

Rep: Reputation: 15
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
 
Old 07-25-2003, 12:35 PM   #5
Deeter
LQ Newbie
 
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 07-25-2003, 12:55 PM   #6
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Rep: Reputation: 46
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 :-)
 
Old 07-28-2003, 06:50 PM   #7
Deeter
LQ Newbie
 
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 07-28-2003, 07:02 PM   #8
Deeter
LQ Newbie
 
Registered: Jul 2003
Location: Pacifica, CA
Distribution: Red Hat 9
Posts: 7

Original Poster
Rep: Reputation: 0
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron.allow and cron.deny in slackware? tl64 Slackware 5 10-13-2005 09:44 PM
No More Cron Mail, Cron Error? Xhost Linux - General 3 07-26-2004 04:28 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration