monitor – Derek Demuro https://www.derekdemuro.com Software Engineer Sat, 12 Dec 2020 23:02:59 +0000 en-US hourly 1 160473225 OpenSuse simple package export script. https://www.derekdemuro.com/2013/08/05/opensuse-simple-package-export-script/ https://www.derekdemuro.com/2013/08/05/opensuse-simple-package-export-script/#respond Mon, 05 Aug 2013 04:17:40 +0000 https://www.derekdemuro.com/?p=1981 OpenSuse package export script, may be used for others with mods. Have saved me a lot of time with migrations.
#!/bin/sh
###############################################
#  Derek Demuro - OpenSUSE Packages Export    #
###############################################
 
# Absolute path to de zypper repositories lists.
readonly reposPath='/etc/zypp/repos.d/'
 
echo 'Welcome to Package Automation V1.1'
 
echo 'Enter 1 to do a full package export with package details'
echo 'Enter 2 to do a exportable package export, to install in another system'
echo 'Enter 3 to install a exported package list in another system'
echo 'Enter 4 to export your repos'
echo 'Enter 5 to import your repos'
echo 'Enter 6 to differ two sources files'
echo 'Enter 7 to quit'
 
PS3='Please enter your choice: '
options=("1" "2" "3" "4" "5" "6" "7")
select opt in "${options[@]}"
do
    case $opt in
        "1")
        echo "You chose 1, we'll do a full package export with description"
        echo 'What name would you like us to use to save the output?'
        read fname
        #Package name: Version : Release : Version Installed
        #Package Ej: yast2-trans-zh_CN:2.22.0:8.7.1:1346256812:YaST2 - Simplified Chinese Translations
        rpm -qa --qf '%{NAME}:%{VERSION}:%{RELEASE}:%{INSTALLTID}:%{SUMMARY}\n' | sort >> $fname
            ;;
        "2")
        echo "You chose 2, we'll do an installable version"
        echo 'What name would you like us to use to save the output?'
        read name
        #For installable version
        rpm -qa --qf '%{NAME}\n' | sort >> $name
            ;;
        "3")
        echo "You chose 3, we'll install all the packages in the file."
        echo 'Select 0 to install everything without confirmation, 1 for confirmation'
 
        read conf
 
        if [ $conf -eq 0 ]
        then
            conf=0
        else
            conf=1
        fi
 
        #Do you want to update your repository list
        echo "If you want to update your package list press 1"
        read update
        if [ $update -eq 1 ]
        then
            zypper ref
        fi
 
        echo 'Please type the name of the file that contains the package list'
        read FILENAME
         
        rpm -qa --qf '%{NAME}\n' | sort > old.txt
         
        diff -Naur old.txt $FILENAME | grep '^+' | sed s/+//g | tail -n +2 > differencesToInstall.txt
         
        FILENAME=differencesToInstall.txt
         
            #Loop untill file provided is okay.
            until [  -f $FILENAME ]; do
                if [ -f $FILENAME ]
                then
                    echo 'File seems to be fine'
                else
                    echo 'Whoops file doesnt seem to exists, please introduce it again'
                    echo 'Please type the name of the file that contains the package list'
                    read FILENAME
                fi
            done
 
        count=0
        #Count how many lines, and start installing
        cat $FILENAME | while read LINE
        do
            let count++
            echo "$count $LINE"
            #Zypper -With no output
            if [ $conf = 0 ]
            then
                #NO CONFIRMATION OR MESSAGES                
                zypper --non-interactive install $LINE
            else
                #NORMAL INSTALL
                zypper install $LINE
            fi
        done
 
        echo -e "\nTotal $count Lines read"
        rm $FILENAME;
            ;;
        "4")
        echo "You chose 4, we'll backup your sources list located at /etc/zypp/repos.d/."
        echo 'Input the full path of the folder where you want them copied'
        read dirtree
        cp /etc/zypp/repos.d/* $dirtree
         
        repoammount=`ls /etc/zypp/repos.d | wc -w`
        copiedamm=`ls $dirtree | wc -w`
        echo 'You had: ' $repoammount 'sources, and we copied: ' $copiedamm
        if [ $repoammount -eq $copiedamm ]
        then
            echo 'Everything seems to be copied'
        else
            echo 'Whoops, seems something is missing'
        fi
    ;;
     
    "5")    
        ########################################################################################
        # IMPORT THE SOURCES LIST                                                              #
        ########################################################################################
        cpCount=0
     
        echo 'Enter the absolute path to the directory containing the .repo files you wish to import.'
        read srcDir
         
        # Make sure there isn't a trailing slash on the path variable.
        echo $srcDir | egrep '.+\/$' >/dev/null
         
        if [ $? -eq 0 ]
        then
        # Remove the trailing slash.
        srcDir=`echo "${srcDir%/}"`
        fi
 
        srcFilesCount=`ls "$srcDir"/*.repo | wc -w`
        srcFilesList=`echo "$srcDir"/*.repo`
         
        for i in $srcFilesList
        do
        cp $i $reposPath
        if [ $? -ne 0 ]
        then
            echo "Something went wrong while copying the following file: $i :("
            break
        fi
        $(( $cpCount++ ))
        done       
     
        echo "We had $srcFilesCount files to copy, and we were able to copy $cpCount files."       
        ;;
    "6")
        ########################################################################################
        # COMPRARE TWO SOURCES FILES                                                           #
        ########################################################################################
        echo 'Type sources file 1'
        read sources1
        echo 'Type sources file 2'
        read sources2
        echo 'Type output file name'
        read filename
        # diff -u $sources1 $sources2 > $filename
        diff -Naur $sources1 $sources2 | grep '^+' | sed s/+//g | tail -n +2 > $filename
        ;;
             
        "7")
            break
            ;;
        *)
            echo 'Invalid option.'
            ;;
    esac
done
Download “Opensuse Package Export Script” OSuse_PkgExport.sh_.zip – Downloaded 462 times – 2.00 KB
]]>
https://www.derekdemuro.com/2013/08/05/opensuse-simple-package-export-script/feed/ 0 1981
Server Monitor little dirty script. https://www.derekdemuro.com/2013/08/02/server-monitor-little-dirty-script/ https://www.derekdemuro.com/2013/08/02/server-monitor-little-dirty-script/#respond Fri, 02 Aug 2013 04:25:28 +0000 https://www.derekdemuro.com/?p=2031 #!/bin/bash ################################################################################ # Derek Demuro, this script is given as is, CopyLEFT # ################################################################################ ################################################################################ # README LEAME # ################################################################################ # This script will keep checking load, and log it. # Once the log hits the high load, its time to shutdown services and recall # memory, this way we avoid running into a kernel panic. # If we had DDOS attack, as services are down, the server won't be killed # Once the attack ends, the load will come down, and the services will load up # again # # The script will be modified later on to use functions, but not for now. ############################To Set Up########################################### # # To set this script up, you'll need to add it to a cronjob to run on boot # Most linux distros will allow a param <a href="https://twitter.com/reboot" class="twitter-atreply ext">@reboot<span class="ext"><span class="element-invisible"> (link is external)</span></span></a> /(path)/servermon.sh # So... crontab -e # At the bottom add: <a href="https://twitter.com/reboot" class="twitter-atreply ext">@reboot<span class="ext"><span class="element-invisible"> (link is external)</span></span></a> /(path)/servermon.sh # REMEMBER TO ADD EXECUTABLE BIT TO THE FILE (777 Permissions) ################################################################################ # SCRIPT CONFIGURATION # ################################################################################ #Initialize counter times=0 #How many times to run before clearing log linestoclear=$1 #Critical load to stop everything and restart highload=$2 #Wait till load gets to this load lowload=$3 #Wait for highload high=$4 #Wait for midload mid=$5 #Wait more for lowload low=$6 ################################################################################ #Log how many lines to log echo 'Script will run ' $1 ' times then will clear itself, High load: ' $highload 'Will wait to: ' $lowload "HighWait: $high, MidWait: $mid, LowWait: $low" while [ 0 ] do #add 1 to times times=`expr $times + 1` #check = load at the moment check=`cat /proc/loadavg | sed 's/\./ /' | awk '{print $1}'` date=`date` #Print of the time the cron started. echo 'Load at the moment' $check 'at date ' $date 'script ran: ' $times ' times' #How many times did it run? if [ $times -eq $linestoclear ] then #Clean the log! echo 'Log cleared' > hsysmon.log echo 'Script will run ' $1 ' times then will clear itself' times=0 fi #If load > 10 if [ $check -gt $highload ] then #Apache STOP var=`service apache2 stop` #Moment of shutdown date=`date` msg='Highload autorestart did run and load average was: ' echo 'At: ' $date 'With load: ' $check 'services shutted down successfoully' #Sleep while HIGH LOAD while [ $check -gt $lowload ] do if [ $check -gt $high ] then sleep $high else if [ $check -gt $mid ] then sleep $mid else if [ $check -gt $low ] then sleep $low else sleep 3 fi fi fi #New check check=`cat /proc/loadavg | sed 's/\./ /' | awk '{print $1}'` done #Continue echo 'Restarting on load: ' $check #Apache START apacheres=`service apache2 start` #Prints echo '#######################Apache Restart Log###########################' echo $apacheres echo '#######################Apache Restart Log###########################' echo '###########-----------------------------------------################' fi #Keep checking load sleep 3 done
]]>
https://www.derekdemuro.com/2013/08/02/server-monitor-little-dirty-script/feed/ 0 2031