Difference between revisions of "UNIX assignments"

From Teknologisk videncenter
Jump to: navigation, search
m (New page: == Network management with ping == Write a bash script that will ping 192.168.142.1, mars.tekkom.dk, 172.16.4.77 '''once''' every minut. If it fails three times in a row (Three minutes) it...)
 
m
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[category:Linux]][[Category:UNIX]]
 
== Network management with ping ==
 
== Network management with ping ==
Write a bash script that will ping 192.168.142.1, mars.tekkom.dk, 172.16.4.77 '''once''' every minut. If it fails three times in a row (Three minutes) it should write to your terminal and send a mail to you. You have to be logged in twice.  
+
Write a bash script that will ping 185.22.74.79 'mars.merhot.dk' '''once''' every minute. If it fails three times in a row (Three minutes) it should write to your terminal and send a mail to you. You have to be logged in twice.  
*One session were you run your program
+
*One session where you run your program
*Another session were you will receive your messages and read your mail
+
*Another session where you will receive your messages and read your mail
 
=== Used programs ===
 
=== Used programs ===
 
*ping
 
*ping
Line 18: Line 19:
 
if ping -c 1 192.168.142.1 >/dev/null
 
if ping -c 1 192.168.142.1 >/dev/null
 
   then echo "Ping succeded."
 
   then echo "Ping succeded."
   else echo "Ping Failed.
+
   else echo "Ping Failed."
 
fi
 
fi
 
</pre>
 
</pre>

Latest revision as of 08:30, 25 September 2019

Network management with ping

Write a bash script that will ping 185.22.74.79 'mars.merhot.dk' once every minute. If it fails three times in a row (Three minutes) it should write to your terminal and send a mail to you. You have to be logged in twice.

  • One session where you run your program
  • Another session where you will receive your messages and read your mail

Used programs

  • ping
  • write
  • mail
  • sleep

Getting started

Use the man pages for ping, write and mail.

[heth@bkshost bin]$ man ping

Experiment with the commands until you know how they work. And make them work for you.
To test if ping failed or succeded you can use if

if ping -c 1 192.168.142.1 >/dev/null
  then echo "Ping succeded."
  else echo "Ping Failed."
fi