LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2014, 04:00 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
Need export PATH=$PATH:


I am obtaining the local and client IPs from this command:

echo $SSH_CONNECTION | awk '{ print $1" "$3}'

It works except when the program is executed via cronjob. What 'export PATH=$PATH:' do I need to get the IPs when the script is run by cron?

Thanks.
 
Old 11-18-2014, 04:20 PM   #2
sdblanchet
LQ Newbie
 
Registered: Nov 2014
Location: Montreal, Qc, CA
Distribution: CentOs 6, 7
Posts: 8

Rep: Reputation: Disabled
1- The command export is used to make available, to user's the environment, the variable exported. In your case the PATH variable.
The PATH variable is/can be however very different for each user. For instance the PATH variable for root will be totally different as the root would get access to admin application paths.

2- If you are running your cron job as root, it is quite possible you do not get the same environment variables.
To verify this, login as a regular user and type the following command in a terminal window
set <enter>

Then, if you can, login as root and do the same. The result will be different and maybe the variable you need is or is not available for root
 
Old 11-18-2014, 04:34 PM   #3
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Actually, I am the only user of this server and my script runs out of /etc/pgm/. I had to use the path: business to get iptables data into my program, so I assumed that I needed something like that to get the SSH_CONNECTION data also.
 
Old 11-18-2014, 07:46 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Relying on the PATH in cron jobs is tricky. Use absolute paths like /use/bin/yourprog.

jlinkels
 
Old 11-19-2014, 06:37 AM   #5
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
Relying on the PATH in cron jobs is tricky. Use absolute paths like /use/bin/yourprog.

jlinkels
The path is actually in my script. I just can't figure out which path to put in it to get the $SSH_CONNECTION command to find and retrieve the IPs. Again, it returns the IPs when executed in the terminal window and when you execute the ./script, but it can't retrieve the $SSH_CONNECTION data when the script is executed by a cron job. I think that I need to find the correct 'export PATH=$PATH:???' to retreive it.
 
Old 11-20-2014, 10:15 AM   #6
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
I was not able to ever find a way to successfully script a $SSH_CONNECTION, but I worked around it by grabbing the last 'Accepted publickey' record in the auth.log.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to export a path sryzdn Linux - Newbie 1 06-23-2013 05:23 AM
Export PATH scucci Linux - Newbie 3 10-28-2009 08:14 PM
Ubuntu 8.04 loses my $PATH. Why do I have to repeatedly export PATH= ? oouc Ubuntu 10 09-13-2009 11:54 PM
export Path=/usr/java:$Path does not seem to work lumix Linux - Newbie 1 03-19-2007 03:11 PM
export path command davidleroux1 Mandriva 8 01-19-2006 08:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:49 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