LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   how can i get ipaddress of my machine by shell scripts (https://www.linuxquestions.org/questions/linux-server-73/how-can-i-get-ipaddress-of-my-machine-by-shell-scripts-899672/)

jsaravana87 08-26-2011 03:09 PM

how can i get ipaddress of my machine by shell scripts
 
Hi,

# ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'+
127.0.01
how can i send the output ip address to mail

mail -s 127.0.0.1

TB0ne 08-26-2011 03:23 PM

Quote:

Originally Posted by arun5002 (Post 4454381)
Hi,

# ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'+
127.0.01
how can i send the output ip address to mail

mail -s 127.0.0.1

Not sure what you're asking here. You've got the command string to get the address...so assign it to a variable in your shell script, and use it as you see fit. If you're asking why the mail command isn't working as you've got it, that's a different issue. You're not specifying a subject (fairly sure you don't want it to be the IP address, but that's where you've put it), a recipient address, or the message body, which will definitely hold things up.

There are THOUSANDS of bash scripting tutorials you can easily find on Google. What have you written so far?

tzakrajs 09-01-2011 06:26 AM

Assuming you have an SMTP server running, you can do this:
Code:

echo "This is the body of the email" | mail -s "This is the subject" rai@email.com


All times are GMT -5. The time now is 04:16 PM.