网 络 中 心
中心简介
网络技术

友 情 链 接
 
 
Linux

Scripts
  日期:2011-12-28     【背景色 杏仁黄 秋叶褐 胭脂红 芥末绿 天蓝 雪青 灰 银河白(默认色) 】  【字体:
 

############################################

Update the Host and Static route file from IPlist file

############################################

PATH=/export/home/ipvk/

FILE=$PATH/host_tmp

while read line ;

do

scp  $FILE root@”$line”:/etc/hosts;

done < $PATH/iplist

Command Line Scripting

bash-2.03# while

> read line;

> do

> ssh root@”$line” /bin/bash <<\EOF

> cat /etc/hosts |wc -l

> EOF

> done < iplist.txt

Warning: ftp_put(): Could not create file. in /public_html/ftp_dircheck.php on line 17

.Finished loading .

#############

PHP Script for FTP

#############

$servername = “ftp.superwebsite.com”;

$ftpUser = “”;

$ftpPass = “”;

$path = “/home/scatcine/public_html/music_folder01″;

$remote_path = “/music_folder01″;

$conn_id = ftp_connect($servername) or die(“

Error connecting to $servername

”);

if(ftp_login($conn_id, $ftpUser, $ftpPass))

{

$dir_handle = opendir($path) or die(“Error opening $path”);

while ($file = readdir($dir_handle)) {

ftp_put($conn_id, $remote_path, $file, FTP_BINARY);

echo “
$file”;

die(“Finished loading $file”);

}

}

?>

########################################
Scripts to restart the service automatically
########################################
#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# ————————————————————————-
# Copyright (c) 2003 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# ————————————————————————-
# This script is part of nixCraft shell script http://en.wikipedia.org/wiki/Shell_script  collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ————————————————————————-
# RHEL / CentOS / Fedora http://en.wikipedia.org/wiki/Fedora  Linux restart command
RESTART=”/sbin/service httpd restart”
# uncomment if you are using Debian / Ubuntu Linux
#RESTART=”/etc/init.d/apache2 restart”
#path to pgrep command
PGREP=”/usr/bin/pgrep”
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD=”httpd”
# find httpd pid
$PGREP ${HTTPD}
if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi
Then setup a cron job like this: (usually in your sa-update file under /etc/cron.d)
*/5 * * * * root /root/restart.sh  >/dev/null 2>&1
#####################
Mail through Exim
#####################
#!/bin/bash
SUBJECT=”This is a test script for SSH Access”
EMAIL=”rkumar@transcomus.com”
EMAILMESSAGE=/tmp/test.txt
echo “To: rkumar@transcomus.com”, “cbellomy@transcomus.com” > $EMAILMESSAGE
#echo “cc: cbellomy@transcomus.com” > $EMAILMESSAGE
echo “Subject: this is a test subject” >> $EMAILMESSAGE
echo “This is a test Email for SSH Access” >> $EMAILMESSAGE
echo “This is email text” >> $EMAILMESSAGE
/opt/csw/sbin/exim -odf “$EMAIL” < $EMAILMESSAGE
##############################################
Run the script by providing the command line argument
##############################################
#!/bin/bash
cat /dev/null > /tmp/output.txt
count=0
while [ $count -lt $1 ]
do
echo “############################### Start of the Output ##################################################” >> /tmp/output.txt
statclient -h hkipnat >> /tmp/output.txt
echo “###############################  $value Output Ends Here ##################################################” >> /tmp/output.txt
sleep 20
count=`expr $count + 1`
done
Perl Script to find out the free space on NRS DB srv
#!/usr/bin/perl
use strict;
use DBI;
my $database_username = “trans_dba”;
my $database_password = “bodaga”;
my $msdsn = q/dbi:ODBC:DSN=crsdb/;
my $dbh = DBI->connect( “dbi:Sybase:crsdb”, ‘trans_dba’, ‘bodaga’ )
or die “ERROR DBI::errstr”;
$dbh->do(“use crsdev”) or die “ERROR DBI::errstr”;
my $query = ‘declare @fspace float
exec look_free_space_db @fspace
print @fspace’;
my $sth = $dbh->prepare($query);
$sth->execute();
print “Disk Space : “;
do {
while(my $d = $sth->fetchrow_arrayref) {
if ($sth->{syb_result_type}==4040){
print join(“t”, @$d),”\n”;
}
}
} while($sth->{syb_more_results});
$sth=undef;
$dbh->disconnect;
############################
TIMEZONE CHECK ON SBC’s
############################
#!/bin/bash
cat /dev/null > /tmp/timezoneinfo
EMAILMESSAGE=/tmp/timezoneinfo
EMAIL=rkumar@transcomus.com
TIMEZONE=`date | awk ‘{ print $5 }’`
if [ $TIMEZONE != "GMT" ]
then
echo “Timezone on `hostname` is not GMT now” > $EMAILMESSAGE
echo “Current TImezone on the `hostname` is `date | awk ‘{ print $5 }’`” >> $EMAILMESSAGE
/usr/bin/mail -s “TimeZone Change information on `hostname`”  $EMAIL < $EMAILMESSAGE
fi



0.10099005699158