├── README ├── arch_check.ksh ├── backup.ksh ├── batch_file_rename.sh ├── bk_daily.sh ├── check_alert_log.sh ├── check_oracle.ksh ├── coalesce.ksh ├── create_me.ksh ├── current_users.ksh ├── exp_using_pipes.ksh ├── format_script.sh ├── homedir_backup.sh ├── kill_oracle.sh ├── last_5_mins.sh ├── loginlog.ksh ├── mkfiles.sh ├── modified_today.sh ├── monitor_slice.ksh ├── myping.sh ├── mysql_backup.sh ├── nddchecker.ksh ├── network.ksh ├── newuser.ksh ├── oracle_connection.sh ├── rename_files.sh ├── show_eri.sh ├── show_hme ├── test_network.ksh ├── transfer_script.sh ├── unix_users_to_sql.ksh ├── users_no_password.sh ├── vosstat.sh └── world_writable.ksh /README: -------------------------------------------------------------------------------- 1 | Here is a detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at craig@geekcomputers.co.uk. 2 | 3 | In the scripts the comments etc are lined up correctly when they are viewed in Notepad++ or vi. This is what I use to code Shell scripts. 4 | 5 | arch_check.ksh - This script checks the archive location for any log files that have not yet been compressed and compresses them. 6 | 7 | backup.ksh - Backup script for root disk 8 | 9 | batch_file_rename.sh - This will batch rename all files from one extension to another 10 | 11 | check_alert_log.sh - Start/stop the perl script to monitor the Oracle Alert Log 12 | 13 | check_oracle.ksh - This script checks the pmon and the listener processes are running on the server 14 | 15 | coalesce.ksh - This script gets the list of the tablespaces within the database and then coalesces them 16 | 17 | create_me.ksh - I use this to create me on new Solaris builds 18 | 19 | current_users.ksh - This will gather information about the users that are currently attached to the database. 20 | 21 | exp_using_pipes.ksh - An example of running an export, compressing on the fly using a pipe 22 | 23 | homedir_backup.ksh - Backs up the user that is running the script home directory, and copy it to another machine 24 | 25 | kill_oracle.sh - This will kill all the oracle processes associated with a given sid 26 | 27 | last_5_mins.sh - Captures just the last five minutes of a given logfile 28 | 29 | loginlog.ksh - This creates the file which tracks failed login attempts after five failed attempts 30 | 31 | modified_today.sh - Lists all the files that have been modified that day 32 | 33 | monitor_slice.ksh - Shows the slice, as well as the GB of space used, as well as the space left, it will loop round and round until you cancel it running 34 | 35 | myping.sh - Prefixes the ping command with a date stamp, you then prove when it was run, works on Solaris and Linux 36 | 37 | mysql_backup.sh - Backup MySQL database, either the full database or just a single database 38 | 39 | nddchecker.ksh - Get Network Card information on Solaris 40 | 41 | network.ksh - Get Network Information 42 | 43 | newuser.ksh - A simple script to create a new OS account 44 | 45 | oracle_connections.sh - This will show all of the client connections to the database 46 | 47 | rename_files.sh - This will rename all of the files in a directory by removing the word you pass to it 48 | 49 | show_eri.sh - Get network information for eri cards 50 | 51 | show_hme.sh - Get network information for hme cards 52 | 53 | test_network.ksh - A quick network test to test the network 54 | 55 | transfer_script.sh - This will send a given script to a certain server once prompted, if it can't find the script it searches for scripts with a similar name 56 | 57 | unix_users_to_sql.ksh - Export UNIX users to sql, you can change the last line if you want the output to go to a file, rather than be inserted straight into the database 58 | 59 | vosstat.sh - Gather OS statistics to place in to the database 60 | 61 | world_writable.ksh - Gather OS statistics to place in to the database 62 | -------------------------------------------------------------------------------- /arch_check.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : arch_check.ksh 4 | # Author : Craig Richards 5 | # Created : 30-Jul-2002 6 | # Last Modified : 7 | # Version : 1.1 8 | 9 | # Modifications : Added ORACLE_SID as $2, also changed the funct_check_params 10 | 11 | # Description : This script checks the archive location for any log files that have not yet been compressed and compresses them. 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() 18 | { 19 | if [ ${NARG} -ne 2 ]; then 20 | echo "Archive Check Failed : Not enough Parameters passed" >> $LOGFILE 21 | exit 1 22 | fi 23 | } 24 | 25 | funct_check_logmode() 26 | { 27 | STATUS=`${ORACLE_HOME}/bin/sqlplus -s << EOF 28 | / 29 | SET HEADING OFF 30 | SET FEEDBACK OFF 31 | SET PAUSE OFF 32 | SELECT Log_mode from v\\$database; 33 | exit 34 | EOF` 35 | if [ $STATUS = "NOARCHIVELOG" ]; then 36 | echo "Archive Check Failed : $ORACLE_SID database is in NOARCHIVE LOG MODE" >> $LOGFILE 37 | exit 1 38 | fi 39 | 40 | } 41 | 42 | funct_gzip_files() 43 | { 44 | for i in `ls $ARCH_DIR/*.arc` 45 | do 46 | PIDS=`$INUSE $i` 47 | if [ $PIDS != 0 ]; then 48 | continue 49 | else 50 | $ZIP $i 51 | fi 52 | done 53 | } 54 | 55 | ################ 56 | # Main Program # 57 | ################ 58 | 59 | # Variable Settings 60 | 61 | NARG=$# 62 | ARCH_DIR=$1 63 | LOGFILE='/admin/output/arch_check1.log' 64 | ZIP='/usr/bin/gzip' 65 | INUSE='/etc/fuser' 66 | integer PIDS 67 | 68 | # Oracle Environment 69 | 70 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 71 | ORACLE_SID=$2 ; export ORACLE_SID 72 | ORACLE_HOME=`sed /#/d ${ORATAB_LOC} | grep $ORACLE_SID | awk -F: '{print $2}'` ; export ORACLE_HOME 73 | 74 | { 75 | funct_check_params 76 | funct_check_logmode 77 | funct_gzip_files 78 | } 79 | 80 | ## End of Script 81 | 82 | -------------------------------------------------------------------------------- /backup.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : backup.ksh 4 | # Author : Craig Richards 5 | # Created : 22-March-2006 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Backup script for root disk 12 | 13 | LOG=/tmp/backuplog 14 | 15 | echo "backup for `date` commencing..." > $LOG 16 | mt -f /dev/rmt/0 rewind 17 | ufsdump 0uf /dev/rmt/0cn / >> $LOG 18 | ufsdump 0uf /dev/rmt/0cn /usr >> $LOG 19 | ufsdump 0uf /dev/rmt/0cn /opt >> $LOG 20 | ufsdump 0uf /dev/rmt/0cn /export/home >> $LOG 21 | echo "Backup has now completed" >> $LOG 22 | -------------------------------------------------------------------------------- /batch_file_rename.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : batch_file_rename.sh 4 | # Author : Craig Richards 5 | # Created : 06-August-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will batch rename all files from one extension to another 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Start of the procedure 18 | { 19 | if [ ${NARG} -lt 3 ]; then # Check there are 3 arguments passed to the script, if not display the help 20 | echo "Usage: $0 directory *.old_extension *.new_extension" 21 | exit 1 # Quit the program 22 | elif # Else if 23 | 24 | # If the argument passed is -h or --h then display the following message in the echo statement 25 | 26 | [[ ${script_name} = "-h" ]] || [[ ${script_name} = "--h" ]]; then 27 | echo "Usage: $0 directory old_extension new_extension" 28 | exit 1 # Quit the program 29 | fi # End of the if statement 30 | } # End of the function 31 | 32 | funct_batch_rename() # Start of the procedure 33 | { 34 | old_ext_cut=$(echo "${old_ext}" | cut -f2 -d .) # Cut just the extension passed, lose the . 35 | new_ext_cut=$(echo "${new_ext}" | cut -f2 -d .) # Cut just the extension passed, lose the . 36 | 37 | # This will carry out the rename 38 | 39 | for file in "$work_dir"/*"$old_ext"; do mv "$file" "$(echo "$file" | sed 's/\(.*\.\)'"$old_ext_cut"'/\1'"$new_ext_cut"/)" ; done 40 | } 41 | 42 | ################ 43 | # Main Program # 44 | ################ 45 | 46 | # Variable Settings 47 | 48 | script_name=$0 49 | work_dir=$1 50 | old_ext=$2 51 | new_ext=$3 52 | NARG=$# 53 | 54 | { # Start the main program 55 | funct_check_params # Call the procedure 56 | funct_batch_rename # Call the procedure 57 | } # End of the main program 58 | 59 | ## End of Script -------------------------------------------------------------------------------- /bk_daily.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ##### NOME: rotina_backup_diario.sh 4 | ##### VERSÃO: 0.1 5 | ##### DESCRIÇÃO: Implementação rotina de backup diario com arquivos modificados##### DATA DA CRIAÇÃO: 14/06/2023 6 | ##### ATUALIZADO EM: 18/08/2023 7 | ##### ESCRITO POR: Natan Ogliari 8 | ##### E-MAIL: natanogliari@gmail.com 9 | ##### DISTRO: Ubuntu GNU/Linux 22.04 10 | ##### LICENÇA: MIT license 11 | ##### PROJETO: https://github.com/OgliariNatan/servidor-file-samba4 12 | #########################Torne o script executável ########## 13 | ## chmod +x novo_script 14 | ############################## 15 | ## Script idealizado para manter uma política de backup dos arquivos 16 | ## compartilhados no Servidor de Arquivos. 17 | ## 18 | ## A linha mais abaixo é uma maneira otimizada de backup, pois realiza 19 | ## a compactação dos arquivos compartilhados e já os coloca na pasta 20 | ## montada referente ao servidor de backup. 21 | ## 22 | ## Opção: [v] exibe o progresso, [p] mantem as permissões 23 | echo -e "Inicializado o backup diario" $(date +%d%m%y) >> /home/servidor/samba/conf/log/log.bk_diario 24 | 25 | # Data de ontem 26 | DATA=$(date -d "yesterday" '+%Y-%m-%d') 27 | 28 | # Criar o backup apenas dos arquivos modificados no dia anterior 29 | 30 | find /home/servidor/samba/data/compartilhados -type f -newermt "$DATA" -print0 | tar --null -czvf /home/servidor/samba/bk_diario/$(date -d "yesterday" +%d%m%y)_backup_diario.tar.gz --files-from=- 31 | #Remove arquivos antigos 32 | 33 | echo -e "Removendo o arquivo\t" $(find /home/servidor/samba/bk_diario/ -mtime +7) >> /home/servidor/samba/conf/log/log.bk_diario 34 | 35 | rm $(find /home/servidor/samba/bk_diario/ -mtime +7) 36 | 37 | 38 | echo -e "Finalizado o backup diario\n" >> /home/servidor/samba/conf/log/log.bk_diario 39 | echo -e "################################" 40 | -------------------------------------------------------------------------------- /check_alert_log.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Script Name : check_alert_log.sh 4 | # Author : Craig Richards 5 | # Created : 2nd July 2008 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Start/stop the perl script to monitor the Oracle Alert Log 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | ################ 18 | # Main Program # 19 | ################ 20 | 21 | # Variable Settings 22 | 23 | case "$1" in 24 | 25 | 'start') 26 | # Start the perl script 27 | if [ -f /admin/scripts/check_alert_log.pl ]; then 28 | echo "Starting check_alert_log.pl" 29 | su - oracle -c "nohup /admin/scripts/check_alert_log.pl &" 30 | fi 31 | ;; 32 | 33 | 'stop') 34 | # Stop the perl script 35 | PID=`/usr/bin/ps -ef -u 0 | /usr/bin/fgrep check_alert_log | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}'` 36 | if [ ! -z "$PID" ] ; then 37 | /usr/bin/kill ${PID} >/dev/null 2>&1 38 | fi 39 | ;; 40 | 41 | *) 42 | echo "usage: /etc/init.d/check_alert_log.sh {start|stop}" 43 | ;; 44 | 45 | esac 46 | 47 | ## End of Script 48 | -------------------------------------------------------------------------------- /check_oracle.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : check_oracle.ksh 4 | # Author : Craig Richards 5 | # Created : 05-Jul-2005 6 | # Last Modified : 7 | # Version : 8 | 9 | # Modifications : 10 | 11 | # Description : This script checks the pmon and the listener processes are running on the server 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_user() 18 | { 19 | if [ `/usr/ucb/whoami` != oracle ] 20 | then echo 'You Must be oracle to execute this script !!!' 21 | exit 99 22 | fi 23 | } 24 | 25 | funct_check_params() 26 | { 27 | if [ ${NARG} -ne 1 ]; then 28 | echo "Check Oracle Failed : Not enough Parameters passed" >> $LOGFILE 29 | exit 1 30 | fi 31 | } 32 | 33 | funct_check_pmon() 34 | { 35 | check_pmon=`ps -ef | grep ${ORACLE_SID} | grep pmon | wc -l`; 36 | err_log=`tail -100 $ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log` 37 | oracle_num=`expr $check_pmon` 38 | 39 | echo $err_log > /tmp/db_err_$ORACLE_SID.log 40 | 41 | if [ $oracle_num -lt 1 ] 42 | then 43 | mailx -s "PMON Process for $ORACLE_SID - Not Running" mail@mailaddress.com < /tmp/db_err_$ORACLE_SID.log 44 | exit 0 45 | fi 46 | } 47 | 48 | ################ 49 | # Main Program # 50 | ################ 51 | 52 | # Variable Settings 53 | 54 | NARG=$# 55 | 56 | # Oracle Environment 57 | 58 | ORACLE_SID=$1 ; export ORACLE_SID 59 | ORACLE_BASE=/opt/oracle ; export ORACLE_BASE 60 | 61 | 62 | { 63 | funct_check_user 64 | funct_check_params 65 | funct_check_pmon 66 | 67 | } 68 | 69 | ## End of Script 70 | -------------------------------------------------------------------------------- /coalesce.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : coalesce.ksh 4 | # Author : Craig Richards 5 | # Created : 02-Oct-2002 6 | # Last Modified : 19 March 2003 7 | # Version : 1.1 8 | 9 | # Modifications : 19-March-2003 Changed to take out username and password to use OS authentication and removed funct_check_params 10 | # 19-March-2003 Changed so you have to add a SID for the script to run 11 | 12 | # Description : This script gets the list of the tablespaces within the database and then coalesces them 13 | 14 | ################################# 15 | # Start of procedures/functions # 16 | ################################# 17 | 18 | funct_check_params() 19 | { 20 | if [ ${NARG} -ne 2 ]; then 21 | echo "Not Enough Parameters Passed - Please Supply Username and Password for connection to the database" 22 | exit 1 23 | fi 24 | } 25 | 26 | funct_get_tablespace() 27 | { 28 | ${ORACLE_HOME}/bin/sqlplus -s / << EOF 29 | SET LINESIZE 200 30 | SET PAUSE OFF 31 | SET HEADING OFF 32 | SET TERMOUT OFF 33 | SET FEEDBACK OFF 34 | SET ECHO OFF 35 | 36 | COLUMN tablespace_name FORMAT A30 37 | 38 | SPOOL $LOG_FILE 39 | 40 | SELECT tablespace_name 41 | FROM dba_tablespaces; 42 | 43 | SPOOL OFF 44 | 45 | EXIT 46 | EOF 47 | } 48 | 49 | funct_coalesce() 50 | { 51 | for NAME in $(cat $LOG_FILE) 52 | do 53 | ${ORACLE_HOME}/bin/sqlplus -s / << EOF 54 | ALTER TABLESPACE $NAME COALESCE; 55 | EOF 56 | done 57 | } 58 | 59 | ################ 60 | # Main Program # 61 | ################ 62 | 63 | # Variable Settings 64 | 65 | NARG=$# 66 | DBAUSER=$1 67 | DBAPASS=$2 68 | DATE=`date +"%d-%b-%Y"` 69 | LOG_FILE="/admin/output/coalesce.lst" 70 | 71 | # Oracle Environment 72 | 73 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 74 | ORACLE_SID=$2 ; export ORACLE_SID 75 | ORACLE_HOME=`sed /#/d ${ORATAB_LOC} | grep $ORACLE_SID | awk -F: '{print $2}'` ; export ORACLE_HOME 76 | 77 | { 78 | touch $LOG_FILE 79 | #funct_check_params 80 | funct_get_tablespace 81 | funct_coalesce >> /admin/output/tblsspc.lst 82 | } 83 | 84 | ## End of Script 85 | 86 | 87 | -------------------------------------------------------------------------------- /create_me.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : create_me.ksh 4 | # Author : Craig Richards 5 | # Created : 11-February-2007 6 | # Last Modified : 7 | # Version : 8 | 9 | # Modifications : 10 | 11 | # Description : I use this to create me on new Solaris builds 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_user() 18 | { 19 | if [ `/usr/ucb/whoami` != root ] 20 | then echo 'You Must be ROOT to execute this script !!!' 21 | exit 99 22 | fi 23 | } 24 | 25 | funct_create_user() 26 | { 27 | cat /etc/passwd | grep craigdba 28 | if [[ $? != 0 ]]; then 29 | useradd -c "Craig Richards - Senior Oracle/Unix Admin" -m -d $HOMEDIR -s $SH $USER 30 | chown $USER $HOMEDIR 31 | fi 32 | } 33 | 34 | 35 | ################ 36 | # Main Program # 37 | ################ 38 | 39 | # Variable Settings 40 | 41 | NARG=$# ; export NARG 42 | DATE=`date +"%d-%B-%Y"` ; export DATE 43 | HOMEDIR=/export/home/craigdba ; export HOMEDIR 44 | SH=/bin/ksh 45 | USER=craigdba 46 | 47 | # Oracle Environment 48 | 49 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 50 | 51 | { 52 | funct_check_user 53 | funct_create_user 54 | } 55 | 56 | ## End of Program 57 | -------------------------------------------------------------------------------- /current_users.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : current_users.ksh 4 | # Author : Craig Richards(CR) 5 | # Created : 21 July 2002 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 31-July-2002 (CR) Re-formatted the script to be inline with the template 10 | # : 15-October-2002 (CR) Changed user script to identify more information 11 | 12 | # Description : This will gather information about the users that are currently attached to the database. 13 | 14 | ################################# 15 | # Start of procedures/functions # 16 | ################################# 17 | 18 | funct_get_users() 19 | { 20 | sqlplus -s / as sysdba<< EOF 21 | SET PAUSE OFF 22 | SET PAGESIZE 200 23 | SET LINESIZE 200 24 | COLUMN username FORMAT A15 25 | SPOOL $INFILE 26 | select s.username, osuser, status, server as "Connect Type", 27 | to_char(logon_time,'fmHH24:MI:SS AM') as "Logon Time", 28 | sid, s.serial#, p.spid as "UNIX Proc" 29 | from v\$session s, v\$process p 30 | where s.paddr = p.addr 31 | and s.username is not null 32 | order by status, s.username, s.program, logon_time; 33 | spool off 34 | EXIT 35 | EOF 36 | } 37 | 38 | funct_mail_file() 39 | { 40 | mailx -s " Current Users " $SALIST < $INFILE 41 | } 42 | 43 | ################ 44 | # Main Program # 45 | ################ 46 | 47 | # Variable Settings 48 | 49 | INFILE=/tmp/current_users.lst 50 | SALIST='dba@whatever.com' 51 | 52 | # Oracle Environment 53 | 54 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 55 | ORACLE_HOME=`sed /#/d ${ORATAB_LOC} | grep $ORACLE_SID | awk -F: '{print $2}'` ; export ORACLE_HOME 56 | 57 | { 58 | funct_get_users 59 | funct_mail_file 60 | } 61 | 62 | ## End of Script 63 | 64 | 65 | -------------------------------------------------------------------------------- /exp_using_pipes.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : exp_using_pipes.ksh 4 | # Author : Craig Richards 5 | # Created : 18 March 2009 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : An example of running an export, compressing on the fly using a pipe 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | export_dump() 18 | { 19 | rm -f $HOME/gzippipe 20 | /usr/sbin/mknod $HOME/gzippipe p 21 | 22 | /opt/gzip124x/bin/gzip -c < $HOME/gzippipe > $EXP_FILE & 23 | 24 | $ORACLE_HOME/bin/exp $DBUSER/$DBPASSWD BUFFER=1000000 COMPRESS=N CONSISTENT=Y CONSTRAINTS=Y \ 25 | FULL=Y GRANTS=Y INDEXES=Y DIRECT=Y LOG=${LOG_FILE} ROWS=Y FILE=${HOME}/gzippipe 26 | 27 | rm -f $HOME/gzippipe 28 | } 29 | 30 | ################ 31 | # Main Program # 32 | ################ 33 | 34 | # Variable Settings 35 | 36 | DBUSER=system 37 | DBPASSWD=manager 38 | EXP_FILE="/export/home/${ORACLE_SID}_full.dmp.gz" 39 | LOG_FILE="${ORACLE_SID}_full.log" 40 | PATH=$PATH:$ORACLE_HOME/bin:/opt/gzip124x/bin 41 | 42 | # Oracle Environment 43 | 44 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 45 | { 46 | export_dump 47 | } 48 | 49 | ## End of Script 50 | -------------------------------------------------------------------------------- /format_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : export_users.ksh 4 | # Author : Craig Richards 5 | # Created : 08-November-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Get a list of the Oracle schemas then export them 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function to check the amount of parameters being passed 18 | { 19 | if [ ${NARG} -ne 1 ]; then 20 | echo "Not enough parameters passed" 21 | echo "call : $0 script name" 22 | exit 1 23 | fi 24 | } 25 | 26 | funct_toUpper() # Function to convert to Uppercase 27 | { 28 | echo $1 | tr "[:lower:]" "[:upper:]" 29 | } 30 | 31 | funct_format() # Function to carry out the formatting 32 | { 33 | for OLD in `cat $my_config/words.txt`; 34 | do 35 | new=`echo $OLD | tr "[:lower:]" "[:upper:]"` 36 | sed -e 's/\<'$OLD'\>/'$new'/g' "$FILENAME" > output.sql && cat output.sql > "$FILENAME" 37 | done 38 | rm output.sql 39 | echo -e "\n[+] $FILENAME has been formatted [+]\n" 40 | } 41 | 42 | ################ 43 | # Main Program # 44 | ################ 45 | 46 | # Variable Settings 47 | 48 | NARG=$# 49 | my_config='/cygdrive/c/users/crichards/Dropbox/config' 50 | FILENAME=$1 51 | 52 | 53 | { 54 | funct_check_params 55 | funct_format 56 | } 57 | 58 | ## End of Script 59 | -------------------------------------------------------------------------------- /homedir_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : homedir_backup.sh 4 | # Author : Craig Richards 5 | # Created : December 4, 2011 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Backs up the user that is running the script home directory, and copy it to another machine 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_home_dir() 18 | { 19 | tar cvpzf - /home/${user} | ssh craigdba@backup "cat > /export/home/craigdba/${host}_${user}_backup.tar.gz" 20 | } 21 | 22 | ################ 23 | # Main Program # 24 | ################ 25 | 26 | # Variable Settings 27 | 28 | host=`hostname` 29 | user=`whoami` 30 | 31 | { 32 | funct_home_dir 33 | } 34 | 35 | ## End of Script 36 | 37 | -------------------------------------------------------------------------------- /kill_oracle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : kill_oracle.sh 4 | # Author : Craig Richards 5 | # Created : 31-May-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will kill all the oracle processes associated with a given sid 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function Name 18 | { # Start of the function 19 | if [ ${NARG} -ne 1 ]; then # If the number of arguments is not one, then output a message 20 | echo "$0 : Not enough Parameters passed, you need to supply an ORACLE_SID" 21 | exit 1 # Quit the program 22 | elif # Else if 23 | 24 | # If the argument passed is -h or --h then display the following message in the echo statement 25 | 26 | [[ ${SID} = "-h" ]] || [[ ${SID} = "--h" ]]; then 27 | echo "Usage: You need to add an ORACLE_SID, e.g $0 BOSSLIVE" 28 | exit 1 # Quit the program 29 | fi # End of the if statement 30 | } # End of the function 31 | 32 | funct_check_user() # Function Name 33 | { # Start of the function 34 | if [ `/usr/ucb/whoami` != 'oracle' ]; then # Check the user is Oracle 35 | echo "Error: you must run this as oracle" # Display a message if its another user 36 | exit 99 # Quit the program 37 | fi 38 | } # End of the function 39 | 40 | funct_kill_oracle() # Function Name 41 | { # Start of the function 42 | get_processes=`ps -ef | grep "ora_" | grep ${SID} | grep -v grep` ; export get_processes # Set the variable get_processes to show the processes that will be killed 43 | echo -e "\nProcesses that will be killed is \n\n ${get_processes}" 44 | ps -ef | grep "ora_" | grep ${SID} | grep -v grep | awk '{print $2}' | xargs kill -9 # Kill all the processes associated with the given sid 45 | } # End of the function 46 | 47 | ################ 48 | # Main Program # 49 | ################ 50 | 51 | # Variable Settings 52 | 53 | SID=$1 # Set the variable KEYWORD as the first argument passed 54 | NARG=$# # Set the variable NARG to a number of arguments on the command line 55 | 56 | { # Start of the main program 57 | funct_check_params # Call the function funct_check_params 58 | funct_check_user # Call the function funct_check_user 59 | funct_kill_oracle # Call the function funct_kill_oracle 60 | } # End of the main program 61 | 62 | ## End of Script 63 | -------------------------------------------------------------------------------- /last_5_mins.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : last_5_mins.sh 4 | # Author : Craig Richards 5 | # Created : November 3, 2011 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Captures just the last five minutes of a given logfile 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function Name 18 | { # Start of the function 19 | if [ ${NARG} -ne 1 ]; then # If no arguments are passed then display the following message 20 | echo "last_5_mins FAILED : Not enough Parameters passed, you need to provide a logfile" 21 | exit 1 # Quit the program 22 | fi 23 | } # End of the function 24 | 25 | funct_last_five() # Function Name 26 | { # Start of the function 27 | NEWFILE=`basename $LOGFILE` # Set a local variable 28 | 29 | e= # Logic to gather the last 5 minutes 30 | for (( i = 5; i >= 0; i-- )) ; do 31 | e='-e /'`date +\%R -d "-$i min"`'/p '$e 32 | done 33 | 34 | grep "^$(date '+%b %e')" $LOGFILE | $(sed -n $e > $NEWLOG) 35 | } 36 | 37 | ################ 38 | # Main Program # 39 | ################ 40 | 41 | # Variable Settings 42 | 43 | LOGFILE=$1 # Set the variable LOGFILE to the filename that is passed when the script is called 44 | NEWLOG=/tmp/last_5_mins_$NEWFILE # Set the variable NEWLOG, this is a new file just containing the last 5 minutes 45 | NARG=$# # Check the number of arguments passed to the script 46 | 47 | { 48 | funct_check_params # Call the function 49 | funct_last_five # Call the function 50 | } 51 | 52 | ## End of Script 53 | -------------------------------------------------------------------------------- /loginlog.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : loginlog.ksh 4 | # Author : Craig Richards 5 | # Created : 8 November 2004 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This creates the file which tracks failed login attempts after five failed attempts 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_user() 18 | { 19 | if [ `whoami` != root ] 20 | then echo 'You Must be root to execute this script !!!' 21 | exit 99 22 | fi 23 | } 24 | 25 | funct_loginlog() 26 | { 27 | touch /var/adm/loginlog 28 | chown root /var/adm/loginlog 29 | chgrp sys /var/adm/loginlog 30 | chmod 600 /var/adm/loginlog 31 | } 32 | 33 | ################ 34 | # Main Program # 35 | ################ 36 | 37 | # Variable Settings 38 | 39 | # Oracle Environment 40 | 41 | 42 | { 43 | funct_check_user 44 | funct_loginlog 45 | } 46 | 47 | ## End of Script 48 | 49 | -------------------------------------------------------------------------------- /mkfiles.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # Script Name : mkfiles.sh 4 | # Author : Craig Richards 5 | # Created : 30-October-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will create several 100Mb files 12 | 13 | i=0 14 | while [ $i -lt 11 ] 15 | do 16 | dd if=/dev/zero of=/file_$i bs=1024 count=10000 17 | i=$[ $i + 1 ] 18 | done 19 | -------------------------------------------------------------------------------- /modified_today.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : modified_today.sh 4 | # Author : Craig Richards 5 | # Created : 20-February-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Lists all the files that have been modified that day 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function Name 18 | { # Start of the function 19 | if [ ${NARG} -ne 1 ]; then # If the number of arguments is not one, then output a message 20 | echo "$0 : Not enough Parameters passed, you need to supply a directory" 21 | exit 1 # Quit the program 22 | elif 23 | 24 | # If the argument passed is -h or --h then display the following message in the echo statement 25 | 26 | [[ ${SLICE} = "-h" ]] || [[ ${SLICE} = "--h" ]]; then 27 | echo "Usage: You need to add a slice after the script name, e.g $0 /opt" 28 | exit 1 # Quit the program 29 | fi # End of the if statement 30 | } # End of the function 31 | 32 | funct_find_files() # Function Name 33 | { # Start of the function 34 | find $SLICE -type f -mtime -1 > $LOGFILE # Find all the files and put them into a logfile 35 | 36 | for files in $(cat $LOGFILE) # Loop through all the files and show a long listing 37 | do 38 | ls -l $files 39 | done 40 | } # End of the function 41 | 42 | ################ 43 | # Main Program # 44 | ################ 45 | 46 | # Variable Settings 47 | 48 | DATE=`date +"%d-%B-%Y"` ; export DATE # Set the DATE variable, format it as 20-February-2012 49 | SLICE=$1 # Set the variable SLICE as the first argument passed 50 | LOGFILE=/tmp/modifed_$DATE.log # Set the variable LOGFILE, the stores the files found 51 | NARG=$# # Set the variable NARG to a number of arguments on the command line 52 | 53 | { # Start of the main program 54 | funct_check_params # Call the function funct_check_params 55 | funct_find_files # Call the function funct_file_files 56 | } # End of the main program 57 | 58 | ## End of Script 59 | -------------------------------------------------------------------------------- /monitor_slice.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : monitor_slice.ksh 4 | # Author : Craig Richards 5 | # Created : 14-June-2006 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Shows the slice, as well as the GB of space used, as well as the space left, it will loop round and round until you cancel it running 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() 18 | { 19 | if [ ${NARG} -ne 1 ]; then 20 | echo "Monitor Slice Failed : You need to enter the slice you want to monitor" >> $LOGFILE 21 | exit 1 22 | fi 23 | } 24 | 25 | funct_check_slice() 26 | { 27 | AVAIL=`df -k ${SLICE}| cut -f1 -d"l"| awk '{ print $4 }'` ; export AVAIL 28 | echo "Slice \t\t GB Used" 29 | echo "===== \t\t =======" 30 | while [[ 1 == 1 ]]; 31 | do 32 | du -ks ${SLICE} | awk '{ print $2 "\t" $1/(1024*1024) }' 33 | sleep 30 34 | echo " Space left in KB on ${SLICE} :" ${AVAIL} 35 | done 36 | } 37 | 38 | ################ 39 | # Main Program # 40 | ################ 41 | 42 | # Variable Settings 43 | 44 | NARG=$# ; export NARG 45 | DATE=`date +"%d-%B-%Y"` ; export DATE 46 | SLICE=$1 ; export SLICE 47 | 48 | # Oracle Environment 49 | 50 | { 51 | funct_check_params 52 | funct_check_slice 53 | } 54 | 55 | ## End of Script 56 | 57 | -------------------------------------------------------------------------------- /myping.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : myping.bash 4 | # Author : Craig Richards 5 | # Created : September 25, 2011 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Prefixes the ping command with a date stamp, you then prove when it was run, works on Solaris and Linux 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() 18 | { 19 | if [ ${NARG} -ne 1 ]; then 20 | echo "myping failed : Not enough Parameters passed, you need to add an IP address" 21 | exit 1 22 | fi 23 | } 24 | 25 | funct_SunOS() 26 | { 27 | ping -s $IP | while read pong; do echo "$(date +%F_%T) -- $pong"; done 28 | } 29 | 30 | funct_Linux() 31 | { 32 | ping $IP | while read pong; do echo "$(date +%F_%T) -- $pong"; done 33 | } 34 | 35 | ################ 36 | # Main Program # 37 | ################ 38 | 39 | # Variable Settings 40 | 41 | NARG=$# 42 | IP=$1 43 | 44 | { 45 | funct_check_params 46 | if [[ `uname -s` == 'Linux' ]]; then 47 | funct_Linux 48 | elif [[ `uname -s` == 'SunOS' ]]; then 49 | funct_SunOS 50 | fi 51 | } 52 | 53 | ## End of Script 54 | 55 | -------------------------------------------------------------------------------- /mysql_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : mysql_backup.sh 4 | # Author : Craig Richards 5 | # Created : 08-March-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Backup MySQL database, either the full database or just a single database 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function Name 18 | { # Start of the function 19 | if [ ${NARG} -lt 1 ]; then # If the number of arguments is not one, then output a message 20 | echo "Usage: $0 argument" 21 | echo "full = Full MySQL Backup" 22 | echo "db dbname = Single Database backup" 23 | exit 1 # Quit the program 24 | elif 25 | 26 | # If the argument passed is -h or --h then display the following message in the echo statement 27 | 28 | [[ ${choice} = "-h" ]] || [[ ${choice} = "--h" ]]; then 29 | echo "Usage: $0 argument" 30 | echo "full = Full MySQL Backup" 31 | echo "db dbname = Single Database backup" 32 | exit 1 # Quit the program 33 | fi # End of the if statement 34 | } # End of the function 35 | 36 | funct_backup() # Function Name 37 | { # Start of the function 38 | if [ ${choice} = "full" ]; then # If the choice is full, then.. 39 | mkdir -p ${BACKUP_DIR} # Make the backup directory 40 | 41 | # Run the command to backup ALL the databases in MySQL, timestamp the file to the dated folder 42 | 43 | mysqldump --all-databases | gzip > ${BACKUP_DIR}/full_mysql_backup-`date +%H:%M`.gz 44 | elif # Or 45 | [[ ${choice} = "db" ]]; then # If the choice is db, then.. 46 | mkdir -p ${BACKUP_DIR} # Make the backup directory 47 | 48 | # Backup just the given database, timestamp the file to the dated folder 49 | 50 | mysqldump ${dbbkup} | gzip > ${BACKUP_DIR}/${dbbkup}_mysql_backup-`date +%H:%M`.gz 51 | fi 52 | } # End of the function 53 | 54 | 55 | ################ 56 | # Main Program # 57 | ################ 58 | 59 | # Variable Settings 60 | 61 | DATE=`date +"%d-%B-%Y"` ; export DATE # Set the DATE variable, format it as 20-February-2012 62 | choice=$1 # Set the variable choice as the first argument passed 63 | dbbkup=$2 # Set the variable dbbkup as the database to backup 64 | NARG=$# # Set the variable NARG to a number of arguments on the command line 65 | 66 | { # Start of the main program 67 | funct_check_params # Call the function funct_check_params 68 | funct_backup # Call the function funct_backup 69 | } # End of the main program 70 | 71 | ## End of Script 72 | 73 | -------------------------------------------------------------------------------- /nddchecker.ksh: -------------------------------------------------------------------------------- 1 | ## 2 | #!/bin/sh 3 | 4 | # Print column header information 5 | /usr/bin/echo "Interface\tSpeed\t\tDuplex" 6 | /usr/bin/echo "---------\t-----\t\t------" 7 | 8 | # Determine the speed and duplex for each live NIC on the system 9 | for INTERFACE in `/usr/bin/netstat -i | /usr/bin/egrep -v "^Name|^lo0" \ 10 | | /usr/bin/awk '{print $1}' | /usr/bin/cut -d: -f1 |/usr/bin/sort \ 11 | | /usr/bin/uniq` 12 | do 13 | # "ce" interfaces 14 | if [ "`/usr/bin/echo $INTERFACE \ 15 | | /usr/bin/awk '/^ce[0-9]+/ { print }'`" ] ; then 16 | # Determine the ce interface number 17 | INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 3-` 18 | DUPLEX=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_duplex \ 19 | | /usr/bin/awk '{ print $2 }'` 20 | case "$DUPLEX" in 21 | 1) DUPLEX="half" ;; 22 | 2) DUPLEX="full" ;; 23 | esac 24 | SPEED=`/usr/bin/kstat ce:$INSTANCE | /usr/bin/grep link_speed \ 25 | | /usr/bin/awk '{ print $2 }'` 26 | case "$SPEED" in 27 | 10) SPEED="10 Mbit/s" ;; 28 | 100) SPEED="100 Mbit/s" ;; 29 | 1000) SPEED="1 Gbit/s" ;; 30 | esac 31 | # "bge" interfaces 32 | elif [ "`/usr/bin/echo $INTERFACE \ 33 | | /usr/bin/awk '/^bge[0-9]+/ { print }'`" ] ; then 34 | # Determine the bge interface number 35 | INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 4-` 36 | DUPLEX=`/usr/bin/kstat bge:$INSTANCE:parameters \ 37 | | /usr/bin/grep link_duplex | /usr/bin/awk '{ print $2 }'` 38 | case "$DUPLEX" in 39 | 1) DUPLEX="half" ;; 40 | 2) DUPLEX="full" ;; 41 | esac 42 | SPEED=`/usr/bin/kstat bge:$INSTANCE:parameters \ 43 | | /usr/bin/grep link_speed | /usr/bin/awk '{ print $2 }'` 44 | case "$SPEED" in 45 | 10) SPEED="10 Mbit/s" ;; 46 | 100) SPEED="100 Mbit/s" ;; 47 | 1000) SPEED="1 Gbit/s" ;; 48 | esac 49 | # "iprb" interfaces 50 | elif [ "`/usr/bin/echo $INTERFACE \ 51 | | /usr/bin/awk '/^iprb[0-9]+/ { print }'`" ] ; then 52 | # Determine the iprb interface number 53 | INSTANCE=`/usr/bin/echo $INTERFACE | cut -c 5-` 54 | DUPLEX=`/usr/bin/kstat iprb:$INSTANCE \ 55 | | /usr/bin/grep duplex | /usr/bin/awk '{ print $2 }'` 56 | SPEED=`/usr/bin/kstat iprb:$INSTANCE | /usr/bin/grep ifspeed \ 57 | | /usr/bin/awk '{ print $2 }'` 58 | case "$SPEED" in 59 | 10000000) SPEED="10 Mbit/s" ;; 60 | 100000000) SPEED="100 Mbit/s" ;; 61 | 1000000000) SPEED="1 Gbit/s" ;; 62 | esac 63 | # le interfaces are always 10 Mbit half-duplex 64 | elif [ "`/usr/bin/echo $INTERFACE \ 65 | | /usr/bin/awk '/^le[0-9]+/ { print }'`" ] ; then 66 | DUPLEX="half" 67 | SPEED="10 Mbit/s" 68 | # All other interfaces 69 | else 70 | INTERFACE_TYPE=`/usr/bin/echo $INTERFACE | /usr/bin/sed -e "s/[0-9]*$//"` 71 | INSTANCE=`/usr/bin/echo $INTERFACE | /usr/bin/sed -e "s/^[a-z]*//"` 72 | # Only the root user can run /usr/sbin/ndd commands 73 | if [ "`/usr/bin/id | /usr/bin/cut -c1-5`" != "uid=0" ] ; then 74 | echo "You must be the root user to determine \ 75 | ${INTERFACE_TYPE}${INSTANCE} speed and duplex information." 76 | continue 77 | fi 78 | /usr/sbin/ndd -set /dev/$INTERFACE_TYPE instance $INSTANCE 79 | SPEED=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_speed` 80 | case "$SPEED" in 81 | 0) SPEED="10 Mbit/s" ;; 82 | 1) SPEED="100 Mbit/s" ;; 83 | 1000) SPEED="1 Gbit/s" ;; 84 | esac 85 | DUPLEX=`/usr/sbin/ndd -get /dev/$INTERFACE_TYPE link_mode` 86 | case "$DUPLEX" in 87 | 0) DUPLEX="half" ;; 88 | 1) DUPLEX="full" ;; 89 | *) DUPLEX="" ;; 90 | esac 91 | fi 92 | /usr/bin/echo "$INTERFACE\t\t$SPEED\t$DUPLEX" 93 | done 94 | -------------------------------------------------------------------------------- /network.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | #set -x 3 | ################################################################################ 4 | # Simple script to GET stats about network cards 5 | # Should work on hme and qfe. Will NOT change anything. 6 | # Will report on speed and config of all network interfaces. 7 | # Paul Bates 27.03.2000 8 | # James Council 26.09.2001 9 | # - Changed output to one liners. 10 | # - Added IPversion check. 11 | # James Council 10.10.2002 (jamescouncil@yahoo.com) 12 | # - Added test for Cassini Gigabit-Ethernet card (ce_). 13 | # - Added test for GEM Gigabit-Ethernet (ge_) 14 | # - Added test for eri Fast-Ethernet (eri_). 15 | # - Added "Ethernet Address" field. 16 | # - Removed "IPversion" field. 17 | # - Removed checking of a port more than once (i.e. qfe0 qfe0:1) 18 | # James Council 10.25.2002 (jamescouncil@yahoo.com) 19 | # - Fixed 1GB check on ge device. 20 | # James Council 04.02.2003 (jamescouncil@yahoo.com) 21 | # - Added dmfe check (suggested by John W. Rudick, & Erlend Tronsmoen) 22 | # Octave Orgeron 02.06.2004 (unixconsole@yahoo.com) 23 | # - Added bge check (bge_). 24 | # Octave Orgeron 05.18.2005 (unixconsole@yahoo.com) 25 | # - Corrected CE check to use kstat, which is required in Solaris 10. 26 | # Paul Bates 21.11.2005 (sun@paulbates.org) 27 | # - Corrected Cassini GE check to use cap_autoneg not adv_cap_autoneg 28 | # - Thanks to Christian Jose of CSC for finding bug and suggesting fix. 29 | # Octave Orgeron 12.13:2005 (unixconsole@yahoo.com) 30 | # - Corrected DMFE check. Added IPGE check. Special thanks to 31 | # Paul Bates, Christian Jose, and Bill Qualye for suggesting fixes and 32 | # for keeping me on my toes;) 33 | # NOTE: For further updates or comments please feel free to contact me via 34 | # email. James Council or Octave Orgeron 35 | # 36 | ################################################################################ 37 | NDD=/usr/sbin/ndd 38 | KSTAT=/usr/bin/kstat 39 | IFC=/sbin/ifconfig 40 | 41 | typeset -R5 LINK 42 | typeset -R9 AUTOSPEED 43 | typeset -R6 STATUS 44 | typeset -R6 SPEED 45 | typeset -R5 MODE 46 | typeset -R18 ETHER 47 | 48 | #---- Function to test that the user is root. 49 | # 50 | Check_ID() 51 | { 52 | ID=$(/usr/ucb/whoami) 53 | if [ $ID != "root" ]; then 54 | echo "$ID, you must be root to run this program." 55 | exit 1 56 | fi 57 | } 58 | 59 | 60 | #---- Function to test a Intel 82571-based ethernet controller port (i.e. ipge_). 61 | # 62 | Check_IPGE() 63 | { 64 | autospeed=`${KSTAT} -m ipge -i $num -s cap_autoneg | grep cap_autoneg | awk '{print $2}'` 65 | case $autospeed in 66 | 1) AUTOSPEED=on ;; 67 | 0) AUTOSPEED=off ;; 68 | *) AUTOSPEED=Error ;; 69 | esac 70 | 71 | status=`${KSTAT} -m ipge -i $num -s link_up | grep link_up | awk '{print $2}'` 72 | case $status in 73 | 1) STATUS=Up ;; 74 | 0) STATUS=DOWN ;; 75 | *) STATUS=Error ;; 76 | esac 77 | 78 | speed=`${KSTAT} -m ipge -i $num -s link_speed | grep link_speed | awk '{print $2}'` 79 | case $speed in 80 | 1000) SPEED=1GB ;; 81 | 100) SPEED=100MB ;; 82 | 10) SPEED=10MB ;; 83 | 0) SPEED=10MB ;; 84 | *) SPEED=Error ;; 85 | esac 86 | 87 | mode=`${KSTAT} -m ipge -i $num -s link_duplex | grep link_duplex | awk '{print $2}'` 88 | case $mode in 89 | 2) MODE=FDX ;; 90 | 1) MODE=HDX ;; 91 | 0) MODE=--- ;; 92 | *) MODE=Error ;; 93 | esac 94 | } 95 | 96 | #---- Function to test a Cassini Gigabit-Ethernet port (i.e. ce_). 97 | # 98 | Check_CE() 99 | { 100 | autospeed=`${KSTAT} -m ce -i $num -s cap_autoneg | grep cap_autoneg | awk '{print $2}'` 101 | case $autospeed in 102 | 1) AUTOSPEED=on ;; 103 | 0) AUTOSPEED=off ;; 104 | *) AUTOSPEED=Error ;; 105 | esac 106 | 107 | status=`${KSTAT} -m ce -i $num -s link_up | grep link_up | awk '{print $2}'` 108 | case $status in 109 | 1) STATUS=Up ;; 110 | 0) STATUS=DOWN ;; 111 | *) STATUS=Error ;; 112 | esac 113 | 114 | speed=`${KSTAT} -m ce -i $num -s link_speed | grep link_speed | awk '{print $2}'` 115 | case $speed in 116 | 1000) SPEED=1GB ;; 117 | 100) SPEED=100MB ;; 118 | 10) SPEED=10MB ;; 119 | 0) SPEED=10MB ;; 120 | *) SPEED=Error ;; 121 | esac 122 | 123 | mode=`${KSTAT} -m ce -i $num -s link_duplex | grep link_duplex | awk '{print $2}'` 124 | case $mode in 125 | 2) MODE=FDX ;; 126 | 1) MODE=HDX ;; 127 | 0) MODE=--- ;; 128 | *) MODE=Error ;; 129 | esac 130 | } 131 | 132 | 133 | #---- Function to test Quad Fast-Ethernet, Fast-Ethernet, and 134 | # GEM Gigabit-Ethernet (i.e. qfe_, hme_, ge_) 135 | # 136 | Check_NIC() 137 | { 138 | ${NDD} -set /dev/${1} instance ${2} 139 | 140 | if [ $type = "ge" ];then 141 | autospeed=`${NDD} -get /dev/${1} adv_1000autoneg_cap` 142 | else autospeed=`${NDD} -get /dev/${1} adv_autoneg_cap` 143 | fi 144 | case $autospeed in 145 | 1) AUTOSPEED=on ;; 146 | 0) AUTOSPEED=off ;; 147 | *) AUTOSPEED=Error ;; 148 | esac 149 | 150 | status=`${NDD} -get /dev/${1} link_status` 151 | case $status in 152 | 1) STATUS=Up ;; 153 | 0) STATUS=DOWN ;; 154 | *) STATUS=Error ;; 155 | esac 156 | 157 | speed=`${NDD} -get /dev/${1} link_speed` 158 | case $speed in 159 | 1000) SPEED=1GB ;; 160 | 1) SPEED=100MB ;; 161 | 0) SPEED=10MB ;; 162 | *) SPEED=Error ;; 163 | esac 164 | 165 | mode=`${NDD} -get /dev/${1} link_mode` 166 | case $mode in 167 | 1) MODE=FDX ;; 168 | 0) MODE=HDX ;; 169 | *) MODE=Error ;; 170 | esac 171 | } 172 | 173 | #---- Function to test the Davicom Fast Ethernet, DM9102A, devices 174 | # on the Netra X1 and SunFire V100 (i.e. dmfe_) 175 | # 176 | Check_DMF_NIC() 177 | { 178 | autospeed=`${NDD} -get /dev/${1}${2} adv_autoneg_cap` 179 | case $autospeed in 180 | 1) AUTOSPEED=on ;; 181 | 0) AUTOSPEED=off ;; 182 | *) AUTOSPEED=Error ;; 183 | esac 184 | 185 | status=`${NDD} -get /dev/${1}${2} link_status` 186 | case $status in 187 | 1) STATUS=Up ;; 188 | 0) STATUS=DOWN ;; 189 | *) STATUS=Error ;; 190 | esac 191 | 192 | speed=`${NDD} -get /dev/${1}${2} link_speed` 193 | case $speed in 194 | 100) SPEED=100MB ;; 195 | 10) SPEED=10MB ;; 196 | 0) SPEED=10MB ;; 197 | *) SPEED=Error ;; 198 | esac 199 | 200 | mode=`${NDD} -get /dev/${1}${2} link_mode` 201 | case $mode in 202 | 2) MODE=FDX ;; 203 | 1) MODE=HDX ;; 204 | 0) MODE=--- ;; 205 | *) MODE=Error ;; 206 | esac 207 | } 208 | 209 | # Function to detect Sun BGE interface on Sun Fire V210 and V240. 210 | # The BGE is a Broadcom BCM5704 chipset. There are four interfaces 211 | # on the V210 and V240. 212 | Check_BGE_NIC() 213 | { 214 | autospeed=`${NDD} -get /dev/${1}${2} adv_autoneg_cap` 215 | case $autospeed in 216 | 1) AUTOSPEED=on ;; 217 | 0) AUTOSPEED=off ;; 218 | *) AUTOSPEED=Error ;; 219 | esac 220 | 221 | status=`${NDD} -get /dev/${1}${2} link_status` 222 | case $status in 223 | 1) STATUS=Up ;; 224 | 0) STATUS=DOWN ;; 225 | *) STATUS=Error ;; 226 | esac 227 | 228 | speed=`${NDD} -get /dev/${1}${2} link_speed` 229 | case $speed in 230 | 1000) SPEED=1GB ;; 231 | 100) SPEED=100MB ;; 232 | 10) SPEED=10MB ;; 233 | 0) SPEED=10MB ;; 234 | *) SPEED=Error ;; 235 | esac 236 | 237 | mode=`${NDD} -get /dev/${1}${2} link_duplex` 238 | case $mode in 239 | 2) MODE=FDX ;; 240 | 1) MODE=HDX ;; 241 | 0) MODE=--- ;; 242 | *) MODE=Error ;; 243 | esac 244 | } 245 | 246 | ############################################# 247 | # Start 248 | ############################################# 249 | # 250 | Check_ID 251 | 252 | # Output header. 253 | echo 254 | echo " Link Autospeed Status Speed Mode Ethernet Address" 255 | echo "----- --------- ------ ------ ----- ------------------" 256 | 257 | # Create a uniq list of network ports configured on the system. 258 | # 259 | # NOTE: This is done to avoid multiple references to a single network port 260 | # (i.e. qfe0 and qfe0:1). 261 | # 262 | for LINK in `${IFC} -a| egrep -v "lo|be|dman|lpfc"| \ 263 | awk -F: '/^[a-z,A-z]/ {print $1}'| sort -u` 264 | do 265 | type=$(echo $LINK | sed 's/[0-9]//g') 266 | num=$(echo $LINK | sed 's/[a-z,A-Z]//g') 267 | 268 | # Here we reference the functions above to set the variables for each port which 269 | # will be outputted below. 270 | # 271 | case $type in 272 | bge) Check_BGE_NIC $type $num ;; 273 | ce) Check_CE $type $num ;; 274 | dmfe) Check_DMF_NIC $type $num ;; 275 | ipge) Check_IPGE $type $num ;; 276 | *) Check_NIC $type $num ;; 277 | esac 278 | 279 | 280 | # Set ethernet variable and output all findings for a port to the screen. 281 | # 282 | ETHER=`${IFC} ${LINK}| awk '/ether/ {print $2}'` 283 | echo "$LINK $AUTOSPEED $STATUS $SPEED $MODE $ETHER" 284 | done 285 | 286 | set +x 287 | ############################################# 288 | # End 289 | ############################################# 290 | 291 | 292 | 293 | 294 | 295 | ############################################################################## 296 | ### This script is submitted to BigAdmin by a user of the BigAdmin community. 297 | ### Sun Microsystems, Inc. is not responsible for the 298 | ### contents or the code enclosed. 299 | ### 300 | ### 301 | ### Copyright 2006 Sun Microsystems, Inc. ALL RIGHTS RESERVED 302 | ### Use of this software is authorized pursuant to the 303 | ### terms of the license found at 304 | ### http://www.sun.com/bigadmin/common/berkeley_license.html 305 | ############################################################################## 306 | 307 | -------------------------------------------------------------------------------- /newuser.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : newuser.ksh 4 | # Author : Craig Richards 5 | # Created : 10th December 2008 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : A simple script to create a new OS account 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_user() 18 | { 19 | if [ `/usr/ucb/whoami` != root ] 20 | then echo 'You Must be root to execute this script !!!' 21 | exit 99 22 | fi 23 | } 24 | 25 | funct_get_info() 26 | { 27 | clear 28 | print -n "Please enter username of the user to be created : "; 29 | read username 30 | print -n "Please enter a comment for the User : "; 31 | read comment 32 | print -n "Please enter the FULL path for the home directory : "; 33 | read dir 34 | print -n "Please enter the full shell you would like to use eg /bin/ksh for Korn Shell : "; 35 | read shell 36 | } 37 | 38 | funct_create_user() 39 | { 40 | useradd -c "$comment" -m -d $dir -s $shell $username 41 | echo ' '; 42 | echo "User $username has been created on $DATE\n\n"; 43 | echo "You will have to set the password for $username !!!\n\n"; 44 | } 45 | 46 | funct_permission() 47 | { 48 | chmod 700 $dir 49 | } 50 | 51 | funct_password_expiry() 52 | { 53 | passwd -x 90 -n 7 $username 54 | } 55 | 56 | ################ 57 | # Main Program # 58 | ################ 59 | 60 | # Variable Settings 61 | 62 | DATE=`date +"%d-%B-%Y"` ; export DATE 63 | 64 | { 65 | funct_check_user; 66 | funct_get_info; 67 | funct_create_user; 68 | funct_permission; 69 | funct_password_expiry; 70 | } 71 | 72 | 73 | ## End of Program 74 | -------------------------------------------------------------------------------- /oracle_connection.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : oracle_connections.sh 4 | # Author : Craig Richards 5 | # Created : 30-May-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will show all of the client connections to the database 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() # Function Name 18 | { # Start of the function 19 | if [ ${NARG} -ne 1 ]; then # If the number of arguments is not one, then output a message 20 | echo "$0 : Not enough Parameters passed, you need to supply an ORACLE_SID" 21 | exit 1 # Quit the program 22 | elif # Else if 23 | 24 | # If the argument passed is -h or --h then display the following message in the echo statement 25 | 26 | [[ ${SID} = "-h" ]] || [[ ${SID} = "--h" ]]; then 27 | echo "Usage: You need to add an ORACLE_SID, e.g $0 BOSSLIVE" 28 | exit 1 # Quit the program 29 | fi # End of the if statement 30 | } # End of the function 31 | 32 | funct_count_connections() # Function Name 33 | { # Start of the function 34 | numconnections=`ps -ef | grep ${SID}| grep -v grep | grep -v ora_ | wc -l` ; export numconnections # Set the variable numconnections as running the UNIX one liner 35 | echo " You have ${numconnections} connections to the database ${SID}" # Display the amount of connections to the database 36 | } # End of the function 37 | 38 | ################ 39 | # Main Program # 40 | ################ 41 | 42 | # Variable Settings 43 | 44 | SID=$1 # Set the variable KEYWORD as the first argument passed 45 | NARG=$# # Set the variable NARG to a number of arguments on the command line 46 | 47 | { # Start of the main program 48 | funct_check_params # Call the function funct_check_params 49 | funct_count_connections # Call the function funct_file_files 50 | } # End of the main program 51 | 52 | ## End of Script 53 | -------------------------------------------------------------------------------- /rename_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : rename_files.sh 4 | # Author : Craig Richards 5 | # Created : 28-March-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will rename all of the files in a directory by removing the word you pass to it 12 | # : I use this when doing a PITR recovery from one database to a test database. 13 | # : PLEASE NOTE YOU MUST BE CAREFUL RUNNING THIS SCRIPT, IF YOU RUN IT IN ERROR THAT'S YOUR MISTAKE 14 | 15 | ################################# 16 | # Start of procedures/functions # 17 | ################################# 18 | 19 | funct_check_params() # Function Name 20 | { # Start of the function 21 | if [ ${NARG} -ne 1 ]; then # If the number of arguments is not one, then output a message 22 | echo "$0 : Not enough Parameters passed, you need to supply a keyword to remove" 23 | exit 1 # Quit the program 24 | elif 25 | 26 | # If the argument passed is -h or --h then display the following message in the echo statement 27 | 28 | [[ ${KEYWORD} = "-h" ]] || [[ ${KEYWORD} = "--h" ]]; then 29 | echo "Usage: You need to add a keyword after the script name, e.g $0 BOSSLIVE" 30 | exit 1 # Quit the program 31 | fi # End of the if statement 32 | } # End of the function 33 | 34 | funct_move_files() # Function Name 35 | { # Start of the function 36 | for i in `ls *$KEYWORD*` 37 | do 38 | echo $i 39 | mv $i `echo $i | cut -f1,3,4 -d_` 40 | done 41 | } # End of the function 42 | 43 | ################ 44 | # Main Program # 45 | ################ 46 | 47 | # Variable Settings 48 | 49 | DATE=`date +"%d-%B-%Y"` ; export DATE # Set the DATE variable, format it as 20-February-2012 50 | KEYWORD=$1 # Set the variable KEYWORD as the first argument passed 51 | NARG=$# # Set the variable NARG to a number of arguments on the command line 52 | 53 | { # Start of the main program 54 | funct_check_params # Call the function funct_check_params 55 | funct_move_files # Call the function funct_file_files 56 | } # End of the main program 57 | 58 | ## End of Script 59 | -------------------------------------------------------------------------------- /show_eri.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "show_hme, v1.5. Stacey Marshall, 16 April 1998" 3 | # Display HME/network parameters. 4 | # Based on get_hme_parameters, Version 2 by Mark F 26/2/97 5 | # 6 | # 7 | # ****************************************************** 8 | # * * 9 | # * DISCLAIMER * 10 | # * * 11 | # ****************************************************** 12 | # 13 | # 14 | # The contents of this file are intended to be read as an example. 15 | # This is not a supported product of Sun Microsystems and no hotline 16 | # calls will be accepted which directly relate to this information. 17 | # 18 | # NO LIABILITY WILL BE ACCEPTED BY SUN MICROSYSTEMS FOR ANY LOSS (DIRECT 19 | # OR CONSEQUENTIAL) INCURRED IN ANY WAY BY ANY PARTY THROUGH THE USE OF 20 | # THIS INFORMATION. 21 | # 22 | # NO WARRANTY OF ANY SORT IS IMPLIED OR GIVEN FOR ANY CODE DERIVED 23 | # FROM THIS INFORMATION. 24 | # 25 | 26 | # Did ya know on Solaris 2.x you can get simular results with: 27 | # ndd /dev/hme `ndd /dev/hme \? | awk '$1 !~ /\?/ {print $1 "\n" }' | \ 28 | # tee /tmp/hme1` > /tmp/hme2;pr -F -m -t /tmp/hme1 /tmp/hme2 29 | # Stacey, 24/3/97 30 | 31 | # get_ndd_info(): $NDD is set before this routine is called. 32 | # argument 1 is the variable name we are interested in, and 33 | # although not seen here it is used within the $NDD variable. 34 | get_ndd_info(){ 35 | echo "$1|$2|$3|`$NDD`" | \ 36 | awk -F\| \ 37 | 'BEGIN {tab=" "} \ 38 | { 39 | if ( substr($4,length($4),1) == "0" ) { \ 40 | ans=$2 } \ 41 | else if ( substr($4,length($4),1) == "1" ) { ans=$3 } \ 42 | else { ans="("$1" = "$4")" } \ 43 | printf("%s %s(%s = %s)\n",ans, \ 44 | substr(tab,length(ans),50),$1,$4)}' 45 | } 46 | 47 | # 16/Feb/98 : 1.5: INSTANCES should be space separated.... 48 | # 11/Feb/98 : 1.4: Ultra platform reports onboard hme as 'network'! 49 | # get_instances: find the instance numbers of hme cards installed. 50 | get_instances(){ 51 | case $OS in 52 | 5.*) 53 | INSTANCES=`prtconf | nawk -F# '/network/ || /eri/ {printf("%d ",$2)}'` 54 | ## For Solaris testing with no eri... 55 | # INSTANCES=1 56 | ;; 57 | *) 58 | INSTANCES=`echo "hmeps/4X" | adb -k /vmunix /dev/mem | 59 | nawk 'BEGIN { FS = ":"; RS="" } 60 | { print \$NF }' | 61 | nawk '{for (i = 1; i <= NF; i++) { 62 | if ($i != 0) 63 | printf "%s ", $i 64 | }}'` 65 | ;; 66 | ## For SunOS testing with no hme... 67 | # *) INSTANCES=1 68 | esac 69 | } 70 | 71 | set_instance(){ 72 | case $OS in 73 | 5.*) 74 | ## Comment out the following line if testing on Solaris without HME 75 | /usr/sbin/ndd -set /dev/eri instance $1 76 | ;; 77 | *) 78 | get_eri_info $1 79 | ;; 80 | esac 81 | } 82 | 83 | get_eri_info() { 84 | parameters=`echo "$1+0x130/29D" | adb -k /vmunix /dev/mem | nawk '/physmem/ { next } 85 | {print substr($0,index($0,":")+1,length($0))}'` 86 | ## For SunOS testing 87 | # parameters='0 1 0 0 8 4 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 16' 88 | i=0 89 | for param in $parameters ; do 90 | i=`expr $i + 1` 91 | case $i in 92 | 1) HMEtransceiver_inuse=$param ;; 93 | 2) HMElink_status=$param ;; 94 | 3) HMElink_speed=$param ;; 95 | 4) HMElink_mode=$param ;; 96 | 5) HMEipg1=$param ;; 97 | 6) HMEipg2=$param ;; 98 | 7) HMEuse_int_xcvr=$param ;; 99 | 8) HMEpace_size=$param ;; 100 | 9) HMEadv_autoneg_cap=$param ;; 101 | 10) HMEadv_100T4_cap=$param ;; 102 | 11) HMEadv_100fdx_cap=$param ;; 103 | 12) HMEadv_100hdx_cap=$param ;; 104 | 13) HMEadv_10fdx_cap=$param ;; 105 | 14) HMEadv_10hdx_cap=$param ;; 106 | 15) HMEautoneg_cap=$param ;; 107 | 16) HME100T4_cap=$param ;; 108 | 17) HME100fdx_cap=$param ;; 109 | 18) HME100hdx_cap=$param ;; 110 | 19) HME10fdx_cap=$param ;; 111 | 20) HME10hdx_cap=$param ;; 112 | 21) HMElp_autoneg_cap=$param ;; 113 | 22) HMElp_100T4_cap=$param ;; 114 | 23) HMElp_100fdx_cap=$param ;; 115 | 24) HMElp_100hdx_cap=$param ;; 116 | 25) HMElp_10fdx_cap=$param ;; 117 | 26) HMElp_10hdx_cap=$param ;; 118 | 27) HMEinstance=$param ;; 119 | 28) HMElance_mode=$param ;; 120 | 29) HMEipg0=$param ;; 121 | *) ;; 122 | esac 123 | done 124 | } 125 | 126 | check_root_id() 127 | { 128 | # Check that the users id is root 129 | 130 | id | grep root >/dev/null 131 | if [ $? -ne 0 ] 132 | then 133 | echo "Only the super-user can execute this script " 134 | abort 135 | fi 136 | } 137 | 138 | get_version() { 139 | 140 | VERSION=`strings /kernel/drv/eri |grep "FEPS Ethernet Driver"` 141 | 142 | } 143 | 144 | ## 145 | ## Start 146 | ## 147 | 148 | check_root_id 149 | get_version 150 | OS=`uname -r` 151 | 152 | case $OS in 153 | 5.*) 154 | ECHO=/usr/bin/echo 155 | NDD='eval /usr/sbin/ndd /dev/eri $1' 156 | ## For Solaris testing with no HME 157 | # NDD='eval $PWD/ndd /dev/eri $1' 158 | ;; 159 | *) 160 | ECHO=/usr/5bin/echo 161 | NDD='eval eval echo \$HME$1' 162 | ;; 163 | esac 164 | 165 | $ECHO "\t\tConfigured Interfaces:\n" 166 | ifconfig -a 167 | 168 | $ECHO "\n\n\t\tHME $VERSION" 169 | instance=${1} 170 | get_instances 171 | 172 | if [ "$INSTANCES" = "" ] 173 | then 174 | $ECHO "\nNo eri interfaces found on host `uname -n`\n" 175 | exit 176 | fi 177 | echo "Detailing Instances: \"${INSTANCES}\"" 178 | for instance in $INSTANCES 179 | do 180 | $ECHO "\n\nConfiguration of eri card # $instance.\n" 181 | $ECHO "NOTE Parameters MAY NOT be accurate if the card is not connected to a HUB/SWITCH" 182 | $ECHO "or if the interface is unused ( IE: Not plumbed in )." 183 | $ECHO "Try snooping the device to inititalise it." 184 | 185 | $ECHO "\nLink Parameters.\n\n" 186 | set_instance $instance 187 | get_ndd_info link_status "The link is DOWN" "The link is UP" 188 | get_ndd_info link_speed "Speed = 10Mb/S" "Speed = 100Mb/S" 189 | get_ndd_info link_mode "Mode = Half Duplex" "Mode = Full Duplex" 190 | get_ndd_info transceiver_inuse "Using INTERNAL Transiever" "Using EXTERNAL Transiever" 191 | get_ndd_info use_int_xcvr "Use External Tranciever if present" "Only use internal tranciever" 192 | get_ndd_info lance_mode "LANCE mode is DISABLED" "LANCE mode is ENABLED" 193 | get_ndd_info adv_autoneg_cap "Will NOT auto negotiate" "WILL auto negotiate" 194 | get_ndd_info lp_autoneg_cap "Link partner (switch) DOES NOT auto-negotiate" "Link partner (switch) HAS auto-negotiate ability" 195 | 196 | $ECHO "\nMisc parameters.\n\n" 197 | 198 | get_ndd_info pace_size "Number of back to back packets" "Number of back to back packets" 199 | get_ndd_info ipg0 "ipg0" "ipg0" 200 | get_ndd_info ipg1 "ipg1" "ipg1" 201 | get_ndd_info ipg2 "ipg2" "ipg2" 202 | 203 | $ECHO "\nCard is set to advertise the following:\n" 204 | 205 | get_ndd_info adv_100T4_cap "100T4 = NO" "100T4 = YES" 206 | get_ndd_info adv_100fdx_cap "100FDX = NO" "100FDX = YES" 207 | get_ndd_info adv_100hdx_cap "100HDX = NO" "100HDX = YES" 208 | get_ndd_info adv_10fdx_cap "10FDX = NO" "10FDX = YES" 209 | get_ndd_info adv_10hdx_cap "10HDX = NO" "10HDX = YES" 210 | 211 | $ECHO "\nThe card Supports the following:\n" 212 | 213 | get_ndd_info 100T4_cap "100T4 = NO" "100T4 = YES" 214 | get_ndd_info 100fdx_cap "100FDX = NO" "100FDX = YES" 215 | get_ndd_info 100hdx_cap "100HDX = NO" "100HDX = YES" 216 | get_ndd_info 10fdx_cap "10FDX = NO" "10FDX = YES" 217 | get_ndd_info 10hdx_cap "10HDX = NO" "10HDX = YES" 218 | get_ndd_info autoneg_cap "Auto Negotiation = NO" "Auto Negotiation = YES" 219 | 220 | $ECHO "\nThe HUB/SWITCH has advertised the following:\n" 221 | 222 | 223 | get_ndd_info lp_autoneg_cap "Link partner (switch) DOES NOT auto-negotiate" "Link partner (switch) DOES HAVE auto-negotiate ability" 224 | $ECHO "\nThe following are ONLY valid if the Switch/HUB supports Auto Negotiation\n" 225 | 226 | get_ndd_info lp_100T4_cap "100T4 = NO" "100T4 = YES" 227 | get_ndd_info lp_100fdx_cap "100FDX = NO" "100FDX = YES" 228 | get_ndd_info lp_100hdx_cap "100HDX = NO" "100HDX = YES" 229 | get_ndd_info lp_10fdx_cap "10FDX = NO" "10FDX = YES" 230 | get_ndd_info lp_10hdx_cap "10HDX = NO" "10HDX = YES" 231 | 232 | done 233 | -------------------------------------------------------------------------------- /show_hme: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "show_hme, v1.5. Stacey Marshall, 16 April 1998" 3 | # Display HME/network parameters. 4 | # Based on get_hme_parameters, Version 2 by Mark F 26/2/97 5 | # 6 | # 7 | # ****************************************************** 8 | # * * 9 | # * DISCLAIMER * 10 | # * * 11 | # ****************************************************** 12 | # 13 | # 14 | # The contents of this file are intended to be read as an example. 15 | # This is not a supported product of Sun Microsystems and no hotline 16 | # calls will be accepted which directly relate to this information. 17 | # 18 | # NO LIABILITY WILL BE ACCEPTED BY SUN MICROSYSTEMS FOR ANY LOSS (DIRECT 19 | # OR CONSEQUENTIAL) INCURRED IN ANY WAY BY ANY PARTY THROUGH THE USE OF 20 | # THIS INFORMATION. 21 | # 22 | # NO WARRANTY OF ANY SORT IS IMPLIED OR GIVEN FOR ANY CODE DERIVED 23 | # FROM THIS INFORMATION. 24 | # 25 | 26 | # Did ya know on Solaris 2.x you can get simular results with: 27 | # ndd /dev/hme `ndd /dev/hme \? | awk '$1 !~ /\?/ {print $1 "\n" }' | \ 28 | # tee /tmp/hme1` > /tmp/hme2;pr -F -m -t /tmp/hme1 /tmp/hme2 29 | # Stacey, 24/3/97 30 | 31 | # get_ndd_info(): $NDD is set before this routine is called. 32 | # argument 1 is the variable name we are interested in, and 33 | # although not seen here it is used within the $NDD variable. 34 | get_ndd_info(){ 35 | echo "$1|$2|$3|`$NDD`" | \ 36 | awk -F\| \ 37 | 'BEGIN {tab=" "} \ 38 | { 39 | if ( substr($4,length($4),1) == "0" ) { \ 40 | ans=$2 } \ 41 | else if ( substr($4,length($4),1) == "1" ) { ans=$3 } \ 42 | else { ans="("$1" = "$4")" } \ 43 | printf("%s %s(%s = %s)\n",ans, \ 44 | substr(tab,length(ans),50),$1,$4)}' 45 | } 46 | 47 | # 16/Feb/98 : 1.5: INSTANCES should be space separated.... 48 | # 11/Feb/98 : 1.4: Ultra platform reports onboard hme as 'network'! 49 | # get_instances: find the instance numbers of hme cards installed. 50 | get_instances(){ 51 | case $OS in 52 | 5.*) 53 | INSTANCES=`prtconf | nawk -F# '/network/ || /hme/ {printf("%d ",$2)}'` 54 | ## For Solaris testing with no hme... 55 | # INSTANCES=1 56 | ;; 57 | *) 58 | INSTANCES=`echo "hmeps/4X" | adb -k /vmunix /dev/mem | 59 | nawk 'BEGIN { FS = ":"; RS="" } 60 | { print \$NF }' | 61 | nawk '{for (i = 1; i <= NF; i++) { 62 | if ($i != 0) 63 | printf "%s ", $i 64 | }}'` 65 | ;; 66 | ## For SunOS testing with no hme... 67 | # *) INSTANCES=1 68 | esac 69 | } 70 | 71 | set_instance(){ 72 | case $OS in 73 | 5.*) 74 | ## Comment out the following line if testing on Solaris without HME 75 | /usr/sbin/ndd -set /dev/hme instance $1 76 | ;; 77 | *) 78 | get_hme_info $1 79 | ;; 80 | esac 81 | } 82 | 83 | get_hme_info() { 84 | parameters=`echo "$1+0x130/29D" | adb -k /vmunix /dev/mem | nawk '/physmem/ { next } 85 | {print substr($0,index($0,":")+1,length($0))}'` 86 | ## For SunOS testing 87 | # parameters='0 1 0 0 8 4 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 16' 88 | i=0 89 | for param in $parameters ; do 90 | i=`expr $i + 1` 91 | case $i in 92 | 1) HMEtransceiver_inuse=$param ;; 93 | 2) HMElink_status=$param ;; 94 | 3) HMElink_speed=$param ;; 95 | 4) HMElink_mode=$param ;; 96 | 5) HMEipg1=$param ;; 97 | 6) HMEipg2=$param ;; 98 | 7) HMEuse_int_xcvr=$param ;; 99 | 8) HMEpace_size=$param ;; 100 | 9) HMEadv_autoneg_cap=$param ;; 101 | 10) HMEadv_100T4_cap=$param ;; 102 | 11) HMEadv_100fdx_cap=$param ;; 103 | 12) HMEadv_100hdx_cap=$param ;; 104 | 13) HMEadv_10fdx_cap=$param ;; 105 | 14) HMEadv_10hdx_cap=$param ;; 106 | 15) HMEautoneg_cap=$param ;; 107 | 16) HME100T4_cap=$param ;; 108 | 17) HME100fdx_cap=$param ;; 109 | 18) HME100hdx_cap=$param ;; 110 | 19) HME10fdx_cap=$param ;; 111 | 20) HME10hdx_cap=$param ;; 112 | 21) HMElp_autoneg_cap=$param ;; 113 | 22) HMElp_100T4_cap=$param ;; 114 | 23) HMElp_100fdx_cap=$param ;; 115 | 24) HMElp_100hdx_cap=$param ;; 116 | 25) HMElp_10fdx_cap=$param ;; 117 | 26) HMElp_10hdx_cap=$param ;; 118 | 27) HMEinstance=$param ;; 119 | 28) HMElance_mode=$param ;; 120 | 29) HMEipg0=$param ;; 121 | *) ;; 122 | esac 123 | done 124 | } 125 | 126 | check_root_id() 127 | { 128 | # Check that the users id is root 129 | 130 | id | grep root >/dev/null 131 | if [ $? -ne 0 ] 132 | then 133 | echo "Only the super-user can execute this script " 134 | abort 135 | fi 136 | } 137 | 138 | get_version() { 139 | 140 | VERSION=`strings /kernel/drv/hme |grep "FEPS Ethernet Driver"` 141 | 142 | } 143 | 144 | ## 145 | ## Start 146 | ## 147 | 148 | check_root_id 149 | get_version 150 | OS=`uname -r` 151 | 152 | case $OS in 153 | 5.*) 154 | ECHO=/usr/bin/echo 155 | NDD='eval /usr/sbin/ndd /dev/hme $1' 156 | ## For Solaris testing with no HME 157 | # NDD='eval $PWD/ndd /dev/hme $1' 158 | ;; 159 | *) 160 | ECHO=/usr/5bin/echo 161 | NDD='eval eval echo \$HME$1' 162 | ;; 163 | esac 164 | 165 | $ECHO "\t\tConfigured Interfaces:\n" 166 | ifconfig -a 167 | 168 | $ECHO "\n\n\t\tHME $VERSION" 169 | instance=${1} 170 | get_instances 171 | 172 | if [ "$INSTANCES" = "" ] 173 | then 174 | $ECHO "\nNo hme interfaces found on host `uname -n`\n" 175 | exit 176 | fi 177 | echo "Detailing Instances: \"${INSTANCES}\"" 178 | for instance in $INSTANCES 179 | do 180 | $ECHO "\n\nConfiguration of hme card # $instance.\n" 181 | $ECHO "NOTE Parameters MAY NOT be accurate if the card is not connected to a HUB/SWITCH" 182 | $ECHO "or if the interface is unused ( IE: Not plumbed in )." 183 | $ECHO "Try snooping the device to inititalise it." 184 | 185 | $ECHO "\nLink Parameters.\n\n" 186 | set_instance $instance 187 | get_ndd_info link_status "The link is DOWN" "The link is UP" 188 | get_ndd_info link_speed "Speed = 10Mb/S" "Speed = 100Mb/S" 189 | get_ndd_info link_mode "Mode = Half Duplex" "Mode = Full Duplex" 190 | get_ndd_info transceiver_inuse "Using INTERNAL Transiever" "Using EXTERNAL Transiever" 191 | get_ndd_info use_int_xcvr "Use External Tranciever if present" "Only use internal tranciever" 192 | get_ndd_info lance_mode "LANCE mode is DISABLED" "LANCE mode is ENABLED" 193 | get_ndd_info adv_autoneg_cap "Will NOT auto negotiate" "WILL auto negotiate" 194 | get_ndd_info lp_autoneg_cap "Link partner (switch) DOES NOT auto-negotiate" "Link partner (switch) HAS auto-negotiate ability" 195 | 196 | $ECHO "\nMisc parameters.\n\n" 197 | 198 | get_ndd_info pace_size "Number of back to back packets" "Number of back to back packets" 199 | get_ndd_info ipg0 "ipg0" "ipg0" 200 | get_ndd_info ipg1 "ipg1" "ipg1" 201 | get_ndd_info ipg2 "ipg2" "ipg2" 202 | 203 | $ECHO "\nCard is set to advertise the following:\n" 204 | 205 | get_ndd_info adv_100T4_cap "100T4 = NO" "100T4 = YES" 206 | get_ndd_info adv_100fdx_cap "100FDX = NO" "100FDX = YES" 207 | get_ndd_info adv_100hdx_cap "100HDX = NO" "100HDX = YES" 208 | get_ndd_info adv_10fdx_cap "10FDX = NO" "10FDX = YES" 209 | get_ndd_info adv_10hdx_cap "10HDX = NO" "10HDX = YES" 210 | 211 | $ECHO "\nThe card Supports the following:\n" 212 | 213 | get_ndd_info 100T4_cap "100T4 = NO" "100T4 = YES" 214 | get_ndd_info 100fdx_cap "100FDX = NO" "100FDX = YES" 215 | get_ndd_info 100hdx_cap "100HDX = NO" "100HDX = YES" 216 | get_ndd_info 10fdx_cap "10FDX = NO" "10FDX = YES" 217 | get_ndd_info 10hdx_cap "10HDX = NO" "10HDX = YES" 218 | get_ndd_info autoneg_cap "Auto Negotiation = NO" "Auto Negotiation = YES" 219 | 220 | $ECHO "\nThe HUB/SWITCH has advertised the following:\n" 221 | 222 | 223 | get_ndd_info lp_autoneg_cap "Link partner (switch) DOES NOT auto-negotiate" "Link partner (switch) DOES HAVE auto-negotiate ability" 224 | $ECHO "\nThe following are ONLY valid if the Switch/HUB supports Auto Negotiation\n" 225 | 226 | get_ndd_info lp_100T4_cap "100T4 = NO" "100T4 = YES" 227 | get_ndd_info lp_100fdx_cap "100FDX = NO" "100FDX = YES" 228 | get_ndd_info lp_100hdx_cap "100HDX = NO" "100HDX = YES" 229 | get_ndd_info lp_10fdx_cap "10FDX = NO" "10FDX = YES" 230 | get_ndd_info lp_10hdx_cap "10HDX = NO" "10HDX = YES" 231 | 232 | done 233 | -------------------------------------------------------------------------------- /test_network.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : test_network.ksh 4 | # Author : Craig Richards 5 | # Created : 27 August 2010 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : A quick network test to test the network 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | 18 | 19 | ################ 20 | # Main Program # 21 | ################ 22 | 23 | # Variable Settings 24 | 25 | NARG=$# ; export NARG 26 | DATE=`date +"%d-%B-%Y"` ; export DATE 27 | 28 | # Oracle Environment 29 | 30 | while true; 31 | do; 32 | netstat -tn > first; 33 | sleep 1; 34 | netstat -tn > second; 35 | diff first second; 36 | done 37 | 38 | ## End of Program 39 | -------------------------------------------------------------------------------- /transfer_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : transfer_script.sh 4 | # Author : Craig Richards 5 | # Created : 18-July-2012 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : This will send a given script to a certain server once prompted, if it can't find the script it searches for scripts with a similar name 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_params() 18 | { 19 | if [ ${NARG} -lt 1 ]; then 20 | echo "Usage: $0 argument" 21 | echo "Argument = Script Name" 22 | exit 1 23 | elif 24 | 25 | # If the argument passed is -h or --h then display the following message in the echo statement 26 | 27 | [[ ${script_name} = "-h" ]] || [[ ${script_name} = "--h" ]]; then 28 | echo "Usage: $0 argument" 29 | echo "Argument = Script Name" 30 | exit 1 # Quit the program 31 | fi # End of the if statement 32 | } # End of the function 33 | 34 | funct_copy_file() 35 | { 36 | if [ ! -z $transfer_file ]; then 37 | read -p "What server to you want to copy the file to : " SERVER 38 | echo "Sending $transfer_file to $SERVER in /tmp" 39 | scp $transfer_file $SERVER:/tmp 40 | else 41 | echo -e "File does not exist \n" 42 | echo -e "A search for similar files shows :" 43 | no_ext=`echo $script_name | cut -f1 -d.` 44 | #echo $no_ext 45 | new_search=`find ${scripts} -name *$no_ext* -print > /tmp/cr_list.txt` ; export new_search 46 | for files in $(cat /tmp/cr_list.txt) 47 | do 48 | new_files=`basename $files` 49 | echo $new_files 50 | done 51 | echo -e "\nWould you like to use one of these scripts? If so re-run the script and pass the correct script" 52 | fi 53 | } 54 | 55 | ################ 56 | # Main Program # 57 | ################ 58 | 59 | # Variable Settings 60 | 61 | script_name=$1 ; export script_name 62 | scripts=/export/home/craigdba/unicle/scripts ; export scripts 63 | transfer_file=`find ${scripts} -name ${1} -print` ; export transfer_file 64 | NARG=$# 65 | 66 | { 67 | funct_check_params 68 | funct_copy_file 69 | } 70 | 71 | ## End of Script 72 | 73 | -------------------------------------------------------------------------------- /unix_users_to_sql.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : unix_users_to_sql.ksh 4 | # Author : Craig Richards 5 | # Created : 27 August 2010 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Export UNIX users to sql, you can change the last line if you want the output to go to a file, rather than be inserted straight into the database 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | typeset TABLE='PASSWD_FILE' 18 | 19 | passwd_table() 20 | { 21 | print "WHENEVER SQLERROR EXIT" 22 | print "WHENEVER OSERROR EXIT" 23 | print "set autocommit off" 24 | print "create table ${TABLE} 25 | ( 26 | hostname varchar2(50), 27 | user_name varchar2(50), 28 | user_description varchar2(100), 29 | shell varchar2(20) 30 | );" 31 | } 32 | 33 | { 34 | passwd_table 35 | typeset -i COUNT=0 36 | typeset FILE=/etc/passwd 37 | typeset Item1 38 | typeset Item5 39 | typeset Item7 40 | typeset host 41 | cat ${FILE} | while read LINE 42 | do 43 | let COUNT=COUNT+1 44 | Item1=$(print ${LINE} | cut -d':' -f1) 45 | Item5=$(print ${LINE} | cut -d':' -f5) 46 | Item7=$(print ${LINE} | cut -d':' -f7) 47 | host=`hostname` 48 | 49 | print " 50 | insert into ${TABLE} 51 | ( 52 | hostname, 53 | user_name, 54 | user_description, 55 | shell 56 | ) 57 | values 58 | ( 59 | '${host}', 60 | '${Item1}', 61 | '${Item5}', 62 | '${Item7}' 63 | );" 64 | 65 | done 66 | print "commit;" 67 | 68 | print "select * from ${TABLE};" 69 | # Remove the hash from the line below, and has out the SQLPLUS line if you want ithe output to a file 70 | #} > /tmp/insert_passwd.sql 71 | } | sqlplus -s scott/tiger 72 | 73 | ## End of Program 74 | -------------------------------------------------------------------------------- /users_no_password.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : users_no_password.sh 4 | # Author : Craig Richards 5 | # Created : 05-September-2012 6 | # Last Modified : 11-April-2013 7 | # Version : 1.1 8 | 9 | # Modifications : 1.1 - 11-April-2013 - CR - Changed to do an OS check so the same script can be used on either Solaris or Linux 10 | 11 | # Description : This will show all OS accounts that don't have a password set. 12 | 13 | get_user_names(){ 14 | nopass=`passwd -${1}a | grep -o "^.* NP"` 15 | 16 | for i in ${nopass/ /_} 17 | { 18 | nopassnames="${nopassnames:- } $i" 19 | } 20 | } 21 | 22 | if [[ "$OSTYPE" == *linux-gnu* ]]; then 23 | get_user_names S 24 | elif [[ "$OSTYPE" == *sunos* ]]; then 25 | get_user_names s 26 | fi 27 | 28 | if [ -z "$nopassnames" ] 29 | then 30 | echo "Good - All user accounts have a password." 31 | else 32 | echo "ERROR: The users listed below have no password set:"\ 33 | " ${nopassnames//_NP/}" 1>&2 34 | exit 1 35 | fi 36 | -------------------------------------------------------------------------------- /vosstat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script Name : vosstat.sh 4 | # Author : Craig Richards 5 | # Created : 6 | # Last Modified : 7 | # Version : 1.0 8 | 9 | # Modifications : 10 | 11 | # Description : Gather OS statistics to place in to the database 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | 18 | 19 | ################ 20 | # Main Program # 21 | ################ 22 | 23 | # Variable Settings 24 | 25 | NARG=$# ; export NARG 26 | DATE=`date +"%d-%B-%Y"` ; export DATE 27 | 28 | # Oracle Environment 29 | 30 | ORATAB_LOC=/etc/oratab ; export ORATAB_LOC 31 | ORACLE_HOME=`sed /#/d ${ORATAB_LOC} | grep $ORACLE_SID | awk -F: '{print $2}'` ; export ORACLE 32 | 33 | export ORACLE_HOME=/u02/opt/oracle/home/10ghome 34 | export PATH=$ORACLE_HOME/bin:$ORACLE_HOME:$PATH 35 | export ORACLE_SID=DBATEST 36 | 37 | c=0 38 | while [ "$c" -lt "10" ] 39 | do 40 | sqlplus -s / as sysdba @vosstat.sql 41 | ((c=c+1)) 42 | done 43 | 44 | ## End of program 45 | -------------------------------------------------------------------------------- /world_writable.ksh: -------------------------------------------------------------------------------- 1 | #!/bin/ksh 2 | 3 | # Script Name : world_writable.ksh 4 | # Author : Craig Richards 5 | # Created : 28-November-2007 6 | # Last Modified : 28 January 2008 7 | # Version : 1.1 8 | 9 | # Modifications : 28th-Jan-2008 - CR - Added the function to check the user ROOT is running the program 10 | 11 | # Description : Shows all world writable file 12 | 13 | ################################# 14 | # Start of procedures/functions # 15 | ################################# 16 | 17 | funct_check_user() 18 | { 19 | ID=$(/usr/ucb/whoami) 20 | if [ $ID != "root" ]; then 21 | echo "$ID, You must be root to run" 22 | exit 1 23 | fi 24 | } 25 | 26 | find_world_writable_dir() 27 | { 28 | find / -type d -perm -o+w -ls 2> /dev/null 1> $OUTPUT_DIR/world.txt 29 | } 30 | 31 | 32 | ################ 33 | # Main Program # 34 | ################ 35 | 36 | # Variable Settings 37 | 38 | NARG=$# ; export NARG 39 | DATE=`date +"%d-%B-%Y"` ; export DATE 40 | OUTPUT_DIR=/admin/output ; export OUTPUT_DIR 41 | 42 | # Oracle Environment 43 | 44 | { 45 | funct_check_user 46 | find_world_writable_dir 47 | } 48 | 49 | ## End of Program 50 | --------------------------------------------------------------------------------