openafs-part2

  1. iscsiadm -m discovery -t sendtargets -p 172.20.193.40 && sleep 15 && iscsiadm -m node -T iqn.2001-05.com.equallogic:4-42a846-4ee8a9f13-1480000025e58afe-afs50 –login && sleep 15 && mount -a
  2. mailsend.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -w
#
# Program: SMTP mail delivery program
# Date: 17th nov 2008
#
# This script takes an smtp server as its only argument, reads an email
# on standard input, and delivers it to the smtp server for relaying to
# the final destination. For example,
#
# % mailsend.pl smtp.mycompany.com < myemail.txt
#
# Where “myemail.txt” contains the necessary mail headers, as well as
# the body text. For example,
#
# Subject: hello world
# Date: Sun, 16 Nov 2008 16:25:38 +0800
#
# this is my message
#
# Modified by jeffrey 171209
# now can have multiple recipients in the To/Cc field
use Socket ;
# —————————————————————————–
my $timeout = 30 ; # smtp inactivity timeout (seconds)
my $line = “” ; # general purpose line buffer
my $host = “” ; # the remote host that we’ll connect to
my $mail_from = “” ; # “From:” pulled off mail headers
my $rcpt_to = “” ; # “To:” pulled off mail headers
my @header = () ; # array of lines, which form the mail headers
# —————————————————————————–
# This function is supplied a email address in the format
  1. get-mptstatus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# This script uses mpt-status to probe /dev/mptctl to find out status of the LSI HW raid array
MPTSTATUS=”/usr/local/bin/mpt-status”
SMTP_SERVER=”smtp.bii-sg.org”
if [ ! -x $MPTSTATUS ]; then
echo “cannot find $MPTSTATUS”
exit
fi
host $SMTP_SERVER | grep “has address”
if [ $? -ne 0 ]; then
SMTP_SERVER=”123.136.68.157″
fi
cat /proc/kallsyms | grep mptctl > /dev/null
# we check the kernel table symbols, not found then try to load as kernel module.
# so there is no need to modprobe if mptctl is compiled in 🙂
if [ $? -ne 0 ]; then
/sbin/modprobe mptctl
if [ $? -ne 0 ]; then
echo “mptctl module not found, please recompile kernel module”
echo “Look at – <kernelsource>/drivers/message/fusion/Kconfig for details”
exit
fi
fi
sleep 2
if [ ! -e /dev/mptctl ]; then
/bin/mknod /dev/mptctl c 10 220
fi
# get the right “-i <controller_id>”
RUNMPT=`$MPTSTATUS -p | grep ‘mpt-status -i’ | sed ‘s/^.*\(mpt-status -i [0-9]\).*$/\1/’`
STATE=`/usr/local/bin/$RUNMPT | grep -w OPTIMAL | sed ‘s/^.*\(OPTIMAL\).*$/\1/’`
if [ “$STATE” != “OPTIMAL” ]; then
echo “hardware raid degraded on `date`” >> /var/log/messages
# we call sendmail.pl here
HOSTNAME=`hostname -f`
echo “From: [email protected]$HOSTNAME” > /root/bin/alertmail.txt
echo “To: [email protected]” >> /root/bin/alertmail.txt
echo “Subject: mpt-status alert – x4100 hardware raid is degraded” >> /root/bin/alertmail.txt
echo ” ” >> /root/bin/alertmail.txt
echo “$HOSTNAME hardware raid in degraded mode – please replace HDD immediately” >> /root/bin/alertmail.txt
/root/bin/mailsend.pl $SMTP_SERVER < /root/bin/alertmail.txt
fi
  1. iscsi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
mount | grep sdc1 || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/iscsinotmounted.txt
sleep 30 && echo $(date) > /vicepa/date || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/cannotwrite2iscsi.txt
sleep 60 && rm -f /vicepa/date || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/cannotwrite2iscsi.txt
# Joe Smith <[email protected]>
# and it returns :
sub f_email_addr
{
my $addr = $_[0] ;
$addr =~ s/^.+\<//g ;
$addr =~ s/\>.*$//g ;
return ($addr) ;
}
# This function sends a line to the remote smtp server, and reads a reply.
# The first argument is expected to be an established tcp connection. The
# line is supplied as the second argument, and the expected smtp reply
# code (number) is specified as the third argument. If the supplied smtp
# code is received, we return an empty string, otherwise something is
# presumed to have gone wrong and we return the entire reply string.
# Finally, an inactivity timeout is enforced. If triggered, the string
# “inactivity timed out” is returned.
sub f_smtp_dialog
{
my $fd = $_[0] ;
my $msg = $_[1] ;
my $expect = $_[2] ;
my $buf = “” ;
# deliver a message to the remote smtp server, if one is specified.
if (length ($msg) > 0)
{ printf ($fd “$msg”) ; }
eval
{
alarm ($timeout) ;
$buf = <$fd> ;
alarm (0) ;
} ;
if ($buf =~ /^$expect/)
{ return (“”) ; }
chomp ($buf) ;
return ($buf) ;
}
# —————————————————————————–
# check usage first …
if ($#ARGV != 0)
{
printf (“Usage : %s <smtp server> < mail.txt\n”, $0) ;
exit (1) ;
}
# try to read in mail header from stdin.
while ($line = <STDIN>)
{
chomp ($line) ;
if ($line =~ /^To:/)
{
$rcpt_to = $line ;
$rcpt_to =~ s/To: // ;
[email protected]=split(/,/,$rcpt_to);
foreach(@recp){
push(@recp_to, f_email_addr($_));
}
}
if ($line =~ /^Cc:/)
{
my$tline;
$tline=$line ;
$tline=~ s/Cc: // ;
[email protected]=split(/,/,$tline);
foreach(@recp){
push(@recp_to, f_email_addr($_));
}
}
if ($line =~ /^From:/)
{
$mail_from = $line ;
$mail_from =~ s/From: // ;
$mail_from = f_email_addr ($mail_from) ;
}
if ($line =~ /^$/)
{
last ;
}
$header[$#header+1] = $line ;
}
# check that we know who we’re sending mail from, and to.
if (length ($mail_from) < 1)
{
printf (“FATAL! Do not know who this mail is from. No ‘From: xx’.\n”) ;
exit (1) ;
}
if ($#recp_to < 0)
{
printf (“FATAL! Do not know who this mail is to. No ‘To: xx’.\n”) ;
exit (1) ;
}
# now attempt to connect to smtp server.
$host = inet_aton ($ARGV[0]) ||
die (“FATAL! Host not found $ARGV[0],$!”) ;
socket ($SD, PF_INET, SOCK_STREAM, getprotobyname (“tcp”)) ||
die (“FATAL! socket() failed,$!”) ;
eval
{
local $SIG{ALRM} = sub
{ printf (“FATAL! Connect to $ARGV[0] timed out.\n”) ; exit (1) ; } ;
alarm ($timeout) ;
connect ($SD, sockaddr_in (25, inet_aton ($ARGV[0]))) ||
die (“FATAL! Cannot connect to $ARGV[0] on port 25,$!”) ;
alarm (0) ;
} ;
select ($SD) ;
$| = 1 ;
select (STDOUT) ;
# perform the standard dialog with the smtp server.
$line = f_smtp_dialog ($SD, “”, 220) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
$line = f_smtp_dialog ($SD, “HELO localhost\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
$line = f_smtp_dialog ($SD, “MAIL FROM: $mail_from\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
#$line = f_smtp_dialog ($SD, “RCPT TO: $rcpt_to\n”, 250) ;
#if (length ($line) > 0)
# { printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
foreach(@recp_to){
my$k=$_;
#print “k $k\n”;
$line = f_smtp_dialog ($SD, “RCPT TO: $k\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
}
$line = f_smtp_dialog ($SD, “DATA\n”, 354) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
# now print out the mail header and read the rest of the mail body.
foreach (@header)
{ print ($SD “$_\n”) ; }
print ($SD “\n”) ;
while ($line = <STDIN>)
{ print ($SD “$line”) ; }
$line = f_smtp_dialog ($SD, “.\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; }
$line = f_smtp_dialog ($SD, “QUIT\n”, 221) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; }
exit (0) ;