1833854 Members
2829 Online
110063 Solutions
New Discussion

Re: Check IP Address

 
SOLVED
Go to solution
hangyu
Regular Advisor

Check IP Address

I try to add a crontab schedule to checks my IP address " 0 10 * * * who -m > $HOME/my_ipaddress " , but I found that it is not work , it should boz this command is not work for schedule job , can suggest how can I check my current IP address in a crontab job ?
4 REPLIES 4
mobidyc
Trusted Contributor
Solution

Re: Check IP Address

Hello,

what is saying your mail file ?
ie. /var/mail/your_user

Maybe it's a PATH problem.

Regards,
Cedrick Gaillard.
Best regards, Cedrick Gaillard
Ralph Grothe
Honored Contributor

Re: Check IP Address

If you already know the NIC you could parse output of the ifconfig command, like

$ /usr/sbin/ifconfig lan0|awk '$1~/inet/{print$2}'

Otherwise, you could parse output from "netstat -in".

What do you need this for?
Sounds rather like your IP address is only ephemeral, maybe a DHCP assignment or provided by some ISP?
Madness, thy name is system administration
Pete Randall
Outstanding Contributor

Re: Check IP Address

First you should use a full path for your who command: /usr/bin/who -m. Second, it is highly unlikely that $HOME is set. Cron has an extremely minimal environment, the path is very brief and very few variables are set - you need to account for all this in your job.


Pete

Pete
Rasheed Tamton
Honored Contributor

Re: Check IP Address

/usr/bin/who -mR|awk '{print $6}' > /fullpath-of-the-dir/my_ipaddress

e.g.,
if your home dir path is
/home/hangyu
make it
/home/hangyu/my_ipaddress

Cron needs full path of the commands because while it runs; otherwise you should initialise your environment in your script.