performs various sanity checks at network init and if curl fails
[bootcd.git] / initscripts / pl_functions
1 #-*-shell-script-*-
2
3 function verbose_show_message () {
4     echo $(date "+%H:%M:%S") " ==================== " "$@"
5 }
6
7 function verbose_run_command () {
8     echo $(date "+%H:%M:%S") " ========== running" "$@"
9     "$@"
10     echo $(date "+%H:%M:%S") " ==========" "$@" "returned with retcod=$?"
11 }
12
13 function pl_network_sanity_checks () {
14     echo $(date "+%H:%M:%S") " ======================================== BEG SANITY CHECKS"
15     for file in $(ls /etc/resolv.conf /etc/sysconfig/network-scripts/ifcfg-eth* ) ; do 
16         verbose_run_command cat $file
17     done
18     verbose_show_message Loaded modules
19     verbose_run_command lsmod
20     verbose_show_message Configured interfaces
21     verbose_run_command ifconfig
22     verbose_show_message Routing table
23     verbose_run_command netstat -rn
24     verbose_show_message Pinging google public DNS 
25     verbose_run_command ping -c 1 -w 5 8.8.8.8
26     # try to resolve this hostname as that's the one used for ntp
27     dnss=$(grep '^nameserver' /etc/resolv.conf 2>/dev/null | awk '{print $2;}')
28     if [ -z "$dnss" ] ; then
29         # not too helpful, but..
30         verbose_show_message No server found in /etc/resolv.conf - Resolving hostname at the google public DNS
31         verbose_run_command host -W 4 pool.ntp.org 8.8.8.8
32     else
33         for dns in $dnss; do
34             verbose_show_message Resolving hostname at $dns
35             verbose_run_command host -W 4 pool.ntp.org $dns
36         done
37     fi
38     echo $(date "+%H:%M:%S") " ======================================== END SANITY CHECKS"
39 }
40