Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
a simple netcat script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
gothbox
n00b
n00b


Joined: 15 Mar 2005
Posts: 14
Location: Norway

PostPosted: Tue Mar 02, 2010 9:29 pm    Post subject: a simple netcat script Reply with quote

i need some help to put toghether a simple script to check if port 80 is open (netcat?)
# nc -z -v localhost 80
localhost [127.0.0.1] 80 (http) open

and if not , to start a script ...
something to set as a cron job maybe ?
im very new to programming , but this shouldnt be to hard ?

thanks alot :)
_________________
its only wrong if you get caught
Back to top
View user's profile Send private message
Naib
Advocate
Advocate


Joined: 21 May 2004
Posts: 4138
Location: Removed by Neddy

PostPosted: Tue Mar 02, 2010 9:33 pm    Post subject: Reply with quote

if lsof -i :80 >/dev/null; then echo "port 80 in use"; fi
_________________
A free press is the unsleeping guardian of every other right that free men prize; it is the most dangerous foe of tyranny. Where men have the habit of liberty, the Press will continue to be the vigilant guardian of the rights of the ordinary citizen.
Back to top
View user's profile Send private message
gothbox
n00b
n00b


Joined: 15 Mar 2005
Posts: 14
Location: Norway

PostPosted: Tue Mar 02, 2010 9:40 pm    Post subject: Reply with quote

that didnt tell me to much to be honest , what does it do ?
i have a ssh session with tunnels running on my school computer , back home , and i need it to be restarted if either my home pc or school pc goes down..
i have no control from home , and would like the script to be restarted if my home computer goes down f,ex ..
its started each time the school pc boots
_________________
its only wrong if you get caught
Back to top
View user's profile Send private message
Naib
Advocate
Advocate


Joined: 21 May 2004
Posts: 4138
Location: Removed by Neddy

PostPosted: Tue Mar 02, 2010 9:45 pm    Post subject: Reply with quote

it checks if port-80 is open (needs to be run by root since it is a priv port) and if it is prints that str to the screen
_________________
A free press is the unsleeping guardian of every other right that free men prize; it is the most dangerous foe of tyranny. Where men have the habit of liberty, the Press will continue to be the vigilant guardian of the rights of the ordinary citizen.
Back to top
View user's profile Send private message
gothbox
n00b
n00b


Joined: 15 Mar 2005
Posts: 14
Location: Norway

PostPosted: Tue Mar 02, 2010 9:59 pm    Post subject: Reply with quote

hahahahahahahaha!


i love you !!!

this is just what i want !


best wishes :)
_________________
its only wrong if you get caught
Back to top
View user's profile Send private message
Naib
Advocate
Advocate


Joined: 21 May 2004
Posts: 4138
Location: Removed by Neddy

PostPosted: Tue Mar 02, 2010 10:04 pm    Post subject: Reply with quote

:)
_________________
A free press is the unsleeping guardian of every other right that free men prize; it is the most dangerous foe of tyranny. Where men have the habit of liberty, the Press will continue to be the vigilant guardian of the rights of the ordinary citizen.
Back to top
View user's profile Send private message
Ant P.
Advocate
Advocate


Joined: 18 Apr 2009
Posts: 2374
Location: UK

PostPosted: Tue Mar 02, 2010 10:18 pm    Post subject: Reply with quote

This one's longer but it'll work without root:
Code:
if netstat -tuna | grep ':80 .*LISTEN' > /dev/null; then
    # local port 80 is open
else
    # isn't
fi
Back to top
View user's profile Send private message
gothbox
n00b
n00b


Joined: 15 Mar 2005
Posts: 14
Location: Norway

PostPosted: Tue Mar 02, 2010 11:45 pm    Post subject: Reply with quote

ill have a look at it :) thanks alot
_________________
its only wrong if you get caught
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum