1
2
su - $sidadm -c "echo 'd */' | mail -N"
su - $sidadm -c /" cat /dev/null > /var/spool/mail/$sidadm/"
system ( ....... )
su - $sidadm -c /" cat /dev/null > /var/spool/mail/$sidadm/"
su - $sidadm -c \" cat /dev/null > /var/spool/mail/$sidadm\"
1 2
my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); system( $command ) == 0 or die "Failed <$command>: $!";
1
2
3
4
5
6
7
8
$ crontab -l
# run user's script every day at 23:00 and save output as logfile;
# make sure, /var/log/user_script.log is writable or use different path; e.g. /home/user/log/user_script.log
# the directory for the log file must exist!
0 23 * * * /home/user/bin/script >/var/log/user_script.log 2>&1
# or you simply don't care about the output
30 23 * * * /home/user/bin/script >/dev/null 2>&1
1 2 3 4 5 6 7 8 9 10
######################################################################################################### # delete OS mails ######################################################################################################### sub DEL_mail { my $sidadm = $_[0]."adm"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); system( $command ) == 0 or die "Failed <$command>: $!"; #system ("su - $sidadm -c /" echo //'d *//' | mail -N//""); }
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
Bareword found where operator expected at /share/User/test/collector.pl line 189, near "my $command =
(Might be a runaway multi-line // string starting on line 170)
(Do you need to predeclare my?)
Unquoted string "dev" may clash with future reserved word at /share/User/test/collector.pl line 189.
Unquoted string "null" may clash with future reserved word at /share/User/test/collector.pl line 189.
Bareword found where operator expected at /share/User/test/collector.pl line 189, near "/var/spool"
(Missing operator before pool?)
Unquoted string "pool" may clash with future reserved word at /share/User/test/collector.pl line 189.
Unquoted string "mail" may clash with future reserved word at /share/User/test/collector.pl line 189.
String found where operator expected at /share/User/test/collector.pl line 190, near "system( $command
(Might be a runaway multi-line "" string starting on line 189)
(Missing semicolon on previous line?)
Bareword found where operator expected at /share/User/test/collector.pl line 190, near "system( $comma
String found where operator expected at /share/User/test/collector.pl line 191, near "#system (""
(Might be a runaway multi-line "" string starting on line 190)
(Missing semicolon on previous line?)
Bareword found where operator expected at /share/User/test/collector.pl line 191, near "#system ("su"
(Missing operator before su?)
Unquoted string "su" may clash with future reserved word at /share/User/test/collector.pl line 191.
Warning: Use of "-c" without parentheses is ambiguous at /share/User/test/collector.pl line 191.
Unquoted string "mail" may clash with future reserved word at /share/User/test/collector.pl line 191.
Bareword found where operator expected at /share/User/test/collector.pl line 207, near "if (Switch::cas
(Might be a runaway multi-line // string starting on line 191)
(Do you need to predeclare if?)
Unquoted string "etc" may clash with future reserved word at /share/User/test/collector.pl line 207.
Unquoted string "issue" may clash with future reserved word at /share/User/test/collector.pl line 207.
Unquoted string "awk" may clash with future reserved word at /share/User/test/collector.pl line 207.
String found where operator expected at /share/User/test/collector.pl line 207, near "awk '{print \$3,
(Do you need to predeclare awk?)
String found where operator expected at /share/User/test/collector.pl line 209, near "#print ""
(Might be a runaway multi-line "" string starting on line 207)
(Missing semicolon on previous line?)
Scalar found where operator expected at /share/User/test/collector.pl line 209, near "#print "$OS_Level
(Missing operator before $OS_Level?)
Backslash found where operator expected at /share/User/test/collector.pl line 209, near "$OS_Level \"
(Missing operator before \?)
Unquoted string "n" may clash with future reserved word at /share/User/test/collector.pl line 209.
String found where operator expected at /share/User/test/collector.pl line 209, at end of line
(Missing semicolon on previous line?)
syntax error at /share/User/test/collector.pl line 189, near "my $command = qq( su - $sidadm -c "cat /
Can't find string terminator '"' anywhere before EOF at /share/User/test/collector.pl line 209.
1
2
3
Bareword found where operator expected at /share/User/test/collector.pl line 189, near "my $command =
(Might be a runaway multi-line // string starting on line 170)
(Do you need to predeclare my?)
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
######################################################################################################### # get dbhost from /usr/sap/<SID>/SYS/profile/DEFAULT.PFL ######################################################################################################### sub DBhost { my $file = "/usr/sap/$_[0]/SYS/profile/DEFAULT.PFL"; my $search = 'dbhost'; open my $fh, '<', $file or die "open($file,ro) failed: $!"; my $seen = ' '; my $third = ''; LINE: while ( my $line = <$fh> ) { # skip lines without search string next LINE if index( lc($line), lc($search), 0 ) < 0; # extract the third field of line $third = ( split( ' ', $line, ) )[2] // ''; if ($third) { last } # keep the fields uniq #$third unless $third eq $seen; #$seen = $third; } return $third; } ######################################################################################################### # delete OS mails ######################################################################################################### sub DEL_mail { my $sidadm = $_[0]."adm"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); system( $command ) == 0 or die "Failed <$command>: $!"; #system ("su - $sidadm -c /" echo //'d *//' | mail -N//""); } ######################################################################################################### # get OS Level ######################################################################################################### sub OS_Level { my $OS_Level; my $osname=$Config{osname}; #print "$osname \n"; switch ($osname) { case "aix" { $OS_Level = `oslevel -r`; } case "linux" { $OS_Level = `cat /etc/issue| awk '{print \$3, \$7, \$8}'| tr "\n" " "| tr -d [:blank:]`; } } #print "$OS_Level \n"; chomp $OS_Level; return $OS_Level; } exit
linuxerSind vielleicht Tippfehler in der Version, die auf Perl 5.8.8 laufen soll?
Hast Du das Skript zentral geändert und dann kopiert oder auf jedem Host einzeln editiert?
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
use warnings; use strict; use File::Find; use File::Basename; use Config; use Sys::Hostname; use IPC::Open2; use Switch; #use feature 'say'; my ( $variant, $comp, $patch, $OSinfoSum, $osvers ); my ( @OSinfoSum, @ListInstances ); my $host = hostname; my @ExcludeHosts = qw (monrz testlpar dbssaphad nimsrv consdd gangmon dbssapl04 dbssapl05 batch woeora57x meclcaaq inst conti ksmb01 arch backup -clone -rep); ######################################################################################################## # exclude some hosts from collect ######################################################################################################## if ( $host =~ /monrz|testlpar|dbssaphad|nimsrv|consdd|gangmon|dbssapl04|dbssapl05|batch|woeora57x|meclcaaq|inst|conti|ksmb01|arch|backup|-clone|-rep/ ) { exit 0; } ######################################################################################################## # exclude some hosts from collect ###############################:######################################################################### ######################################################################################################## # test the oS ######################################################################################################## $osvers = &OS_Level; my $OSinfo = "$host" . " : " . "$Config{osname}" . " : " . "$osvers"; #print "$OSinfo\n" ; ######################################################################################################### # test the saphostctrl (SAP-System) and use it for Kernel and patchlevel (SID: Instance number : Kernel : Patchlevel ) ######################################################################################################### #@ListInstances = `/usr/sap/hostctrl/exe/saphostctrl -function ListInstances | sed 's/ Inst Info : //'` ; if ( -e "/usr/sap/hostctrl/exe/saphostctrl" ) { @ListInstances = `/usr/sap/hostctrl/exe/saphostctrl -function ListInstances | grep -vE "DAA|DAB" |sed 's/,//g' | awk '{print \$4,":",\$6,":"}'`; chomp(@ListInstances); } else { my $info = $OSinfo . " : : : : :"; push @OSinfoSum, $info; } foreach (@ListInstances) { #print "$_\n"; my $UpperSID = substr( $_, 0, 3 ); my $Instance = substr( $_, 6, 2 ); my $LowerSID = lc $UpperSID; my $sidadm = $LowerSID . "adm"; my $ListInstances = $_; #print "$UpperSID\n"; #print "$LowerSID\n"; #print "$SIDadm\n"; # delete all OS mails &DEL_mail($LowerSID); my $DBhost = &DBhost($UpperSID); #print "$sidadm \n"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); my $disp = `su - $sidadm -c "which disp+work " 2>/dev/null`; my $disp_work_error = $?; #print "error disp+work= $disp_work_error \n"; #print "$disp \n"; if ( $? == 0 ) { #print "$disp \n"; #print "$sidadm\n"; #my @SapKernel_Info = `su - $sidadm -c $disp 2>/dev/null`; my $pid = open( PH, " su - $sidadm -c disp+work 2>/dev/null |" ); # or die $!; my @SapKernel_Info; while (<PH>) { #print "output = $_"; push @SapKernel_Info, $_; } #print join "\n", @SapKernel_Info; foreach (@SapKernel_Info) { if (/kernel make variant/) { $variant = (split)[-1]; } elsif (/compilation mode/) { $comp = (split)[-1]; } elsif (/patch number/) { $patch = (split)[-1]; } } my $info = $OSinfo . " : " . $ListInstances . " " . $variant . " : " . $comp . " : " . $patch . " : " . $DBhost; push @OSinfoSum, $info; undef $variant; undef $comp; undef $patch; } else { my $info = $OSinfo . " : " . $ListInstances . " : : "; push @OSinfoSum, $info; } } ######################################################################################################### # get with saphostctrl DB type , version and patchlevel ######################################################################################################### #my @ListDatabaseSystems = `/usr/sap/hostctrl/exe/saphostctrl -function ListDatabaseSystems | egrep -i "Database name|Instance name" | sed 's/^[ \t]*//'|sed 's/^ +//'` ; #print "\n\n @ListInstances"; print join "\n", @OSinfoSum; print "\n"; #print "\n\n @ListDatabaseSystems"; ######################################################################################################### # get dbhost from /usr/sap/<SID>/SYS/profile/DEFAULT.PFL ######################################################################################################### sub DBhost { my $file = "/usr/sap/$_[0]/SYS/profile/DEFAULT.PFL"; my $search = 'dbhost'; open my $fh, '<', $file or die "open($file,ro) failed: $!"; my $seen = ' '; my $third = ''; LINE: while ( my $line = <$fh> ) { # skip lines without search string next LINE if index( lc($line), lc($search), 0 ) < 0; # extract the third field of line $third = ( split( ' ', $line, ) )[2] // ''; if ($third) { last } # keep the fields uniq #$third unless $third eq $seen; #$seen = $third; } return $third; } ######################################################################################################### # delete OS mails ######################################################################################################### sub DEL_mail { my $sidadm = $_[0] . "adm"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); system($command ) == 0 or die "Failed <$command>: $!"; #system ("su - $sidadm -c /" echo //'d *//' | mail -N//""); } ######################################################################################################### # get OS Level ######################################################################################################### sub OS_Level { my $OS_Level; my $osname = $Config{osname}; #print "$osname \n"; switch ($osname) { case "aix" { $OS_Level = `oslevel -r`; } case "linux" { $OS_Level = `cat /etc/issue| awk '{print \$3, \$7, \$8}'| tr "\n" " "| tr -d [:blank:]`; } } #print "$OS_Level \n"; chomp $OS_Level; return $OS_Level; } exit