Đang chuẩn bị liên kết để tải về tài liệu:
Mastering unix shell scripting p6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Thông báo này simple_SQL_query, chức năng, rằng tuyên bố lệnh sqlplus đòi hỏi một tên người dùng, mật khẩu, và một tên Oracle SID để làm việc. Xem mã chức năng trong Ví dụ 9,7. chức năng simple_SQL_query {USER = oracle passwd = oracle SID = yogidb sqlplus $ {USER} / $ {passwd} @ $ SID@my_sql_query.sql} | 328 Chapter 12 PINGSTAT2 ping_host HOSTPINGING grep transmitted awk print 4 if PINGSTAT2 0 then It REALLY IS unreachable.Notify echo Unreachable echo Unable to ping HOSTPINGING from THISHOST tee -a PING_OUTFILE else echo OK fi else echo OK fi done fi function send_notification if -s PING_OUTFILE -a MAILOUT TRUE then case UNAME in AIx HP-UX Linux SENDMAIL usr sbin sendmail SunOS SENDMAIL usr lib sendmail esac echo nSending e-mail notification SENDMAIL -f randy@ THISHOST MAILLIST PING_OUTFILE fi START of MAIN ping_nodes send_notification End of script Listing 12.1 pingnodes.ksh shell script listing. continued Automated Hosts Pinging with Notification 329 Now we get to the fun stuff Let s start out with the three functions because they do all of the work anyway. The first function is ping_host. The idea here is to set up a case statement and based on the response from the uname command which was assigned to the UNAME variable in the definitions section we execute the specific ping command for the particular Unix flavor. If an unlisted Unix flavor is given an ERROR message is given to the user and this shell script exits with a return code 1. We must do this because we have no idea what the correct syntax for a ping command should be for an unknown operating system. The ping_host function is called from the ping_nodes function on every loop iteration. Inside the ping_nodes function we first ensure that the PINGNODES variable is set to TRUE otherwise the pinging of nodes is disabled. We use the PINGFILE file to load a variable PINGLIST with a list of nodes that we want to ping. This extra step is done to give the user the ability to comment out specific node s in the PINGFILE. Without this ability you would leave the user in a state of annoyance for all of the notifications because of a single node being down for a period of time. The command to strip out the commented lines and leave the remaining nodes in the list is shown here. PINGLIST cat PINGFILE grep -v A Notice