Skip to content

Instantly share code, notes, and snippets.

@SunnyBingoMe
Created November 8, 2012 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SunnyBingoMe/4039762 to your computer and use it in GitHub Desktop.
Save SunnyBingoMe/4039762 to your computer and use it in GitHub Desktop.
Start Dag Cards
#!/bin/bash
thisScriptFilename=`basename $0`
usage="Usage: ./$thisScriptFilename."
dbug=0
dbugOk=0
vbose=0
function say(){
echo $1
}
function sayEqualSign(){
echo -ne "====== "
echo -ne $1
echo -ne " ======\n"
}
function debug(){
if [ $dbug == 1 ] ; then
echo $1
fi
}
function debugOk(){
if [ $dbugOk == 1 ] ; then
echo $1
fi
}
function verbose(){
if [ $vbose == 1 ]; then
echo $1
fi
}
#char types
function echoBold(){
echo $2 -e "\033[1m$1\033[0m"
tput sgr0
}
#colored char (with bold, with bg). 47: white bg
function echoRedAndWhite(){
echo $2 -e '\E[47;31m'"\033[1m$1\033[0m" #31: red char
tput sgr0
}
function echoGreenAndWhite(){
echo $2 -e '\E[47;32m'"\033[1m$1\033[0m" # 32: green char
tput sgr0
}
#colored char (with bold)
function echoRed(){
echo $2 -e "\E[33;31m""\033[1m$1\033[0m" # 31: red char
tput sgr0
}
function echoGreen(){
echo $2 -e "\E[33;32m""\033[1m$1\033[0m" # 32: green char
tput sgr0
}
function echoYellow(){
echo $2 -e "\E[33;33m""\033[1m$1\033[0m" # 33: yellow char
tput sgr0
}
function echoBlue(){
echo $2 -e "\E[33;34m""\033[1m$1\033[0m" # 34: blue char
tput sgr0
}
if [ -ne $USER 'root' ] ; then
print "ERR: permission denied.";
fi
sayEqualSign "starting 3.6"
/home/ats/thesis/dropbox_sync_fs/dag.pl start 3.6
#sayEqualSign "ntpdate -u"
#ntpdate -u time.bth.se
sayEqualSign "ntpd"
#ps aux |grep ntp |grep -v grep |cut -c 9-15 |xargs kill -KILL
#ntpd
ntpq -p
sayEqualSign "dagpps"
dagpps -d /dev/dag0
dagpps -d /dev/dag1
sayEqualSign "dagclock"
dagclock -z dag0
dagclock -z dag1
dagclock -d dag0
dagclock -d dag1
sayEqualSign "dagthree"
dagthree -d /dev/dag0 slen=1520 novarlen
dagthree -d /dev/dag0 -s
dagthree -d /dev/dag1 slen=1520 novarlen
dagthree -d /dev/dag1 -s
#/usr/bin/perl
use strict;
############################## Sunny debug BinSun#mail.com ###################
my $sayOk = 0; my $debug = 1; my $debug2 = 1; my $debugOk = 0; my $debug2Ok = 0;
sub say {foreach (@_){print "$_\n";}} sub nl{say "";}
sub sayOk {if($sayOk){say @_;}} sub endl{print "\n";}
sub debug {if($debug){say @_;}} sub debugOk {if($debugOk){say @_;}}
sub debug2 {if($debug2){say @_;}} sub debug2Ok{if($debug2Ok){say @_;}}
###############################################################################
my $logFile = '/data/qodoh/dag-sync-daily.log';
my $dagLockFile = '/data/qodoh/dag.lock';
my $user = trim(`echo \$USER`);
#say "user:$user.";
if ($user ne 'root'){
say "Permission denied.";
exit (1);
}
my $lockDagTimeOut = lockDag();
if ( $lockDagTimeOut != 0){
system ("echo '
'>> $logFile");
my $tTimestamp = timestampRfc();
system ("echo '[$tTimestamp]' >> $logFile");
#system ("echo -ne 'sleep.' >> $logFile");
system ("echo 'ERR: lockDag() time out $lockDagTimeOut s.' >> $logFile");
exit 1;
}
system ('date +%Y-%m-%d\ %H:%M:%S >> '.$logFile);
system ("echo '====== dagpps ======' >> $logFile");
system ("dagpps -d /dev/dag0 |sed 's/[\|\\\/
-]//g'|sed 's/No pulse/ERR:dag0: No pulse/' >> $logFile");
system ("dagpps -d /dev/dag1 |sed 's/[\|\\\/
-]//g'|sed 's/No pulse/ERR:dag1: No pulse/' >> $logFile");
system ("echo '====== dagclock ======' >> $logFile");
system ("dagclock -z /dev/dag0 >> $logFile");
system ("dagclock -z /dev/dag1 >> $logFile");
system ("dagclock -d /dev/dag0 >> $logFile");
system ("dagclock -d /dev/dag1 >> $logFile");
system ("echo '====== dagthree ======' >> $logFile");
system ("dagthree -d /dev/dag0 -as |sed 's/100/ERR 100/' >> $logFile ;
dagthree -d /dev/dag0 -as |sed 's/100/ERR 100/' >> $logFile ;
dagthree -d /dev/dag1 -as |sed 's/100/ERR 100/' >> $logFile ;
dagthree -d /dev/dag1 -as |sed 's/100/ERR 100/' >> $logFile");
open (FID, $logFile) or die("ERR open file: $logFile, $!. \n");
while (<FID>) {
if ($_ =~ /ERR/) {
system ("echo 'found error, will not unlock. plz manually using EE to replace the err string.' >> $logFile");
exit 1;
}
}
if (unlockDag() != 0){
my $tTimestamp = timestampRfc();
system ("echo '$tTimestamp' >> $logFile");
system ("echo 'ERR: unlockDag() failed, unbelieveable.' >> $logFile");
exit 1;
}
my $tTimestamp = timestampRfc();
system ("echo '[$tTimestamp]' >> $logFile");
system ("echo '
'>> $logFile");
sub lockDag()
{
my $tReturned = '';
my $timeSecond = 0;
while (1){
$tReturned = `cat $dagLockFile`;
chomp ($tReturned);
if ($tReturned == '0'){
system ("echo 1 > $dagLockFile");
return 0;
}else {
#system ("echo -ne 'sleep.' >> $logFile");
sleep (2);
$timeSecond = $timeSecond + 2;
if ($timeSecond > 7200){
return $timeSecond;
}
}
}
}
sub unlockDag()
{
my $tReturned = '';
my $timeSecond = 0;
$tReturned = `cat $dagLockFile`;
if ($tReturned == 1){
system ("echo 0 > $dagLockFile");
return 0;
}else {
return 1;
}
}
# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
# Right trim function to remove trailing whitespace
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
}
sub dns()
{
my $server = gethostbyname($_[0]) or die "ERR: gethostbyname()";
return $server = inet_ntoa($server);
}
sub timestampRfc {
my ($sec,$min, $hour, $mday, $mon,$year,$wday,$yday,$isdst);
($sec,$min, $hour, $mday, $mon,$year,$wday,$yday,$isdst)=localtime(time);
$year+=1900;
$mon+=1;
return "$year-$mon-$mday"." $hour:$min:$sec";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment