Basically i am trying to get platform' specific information through the use of the script.
The platform could be: SunOS, AIX or RHEL.
The script does not take any argument in input. It visualise on the screen the success or not of the platform' specific commands which are executed for gathering platform specific information.
The script create, in the directortory where it is launched, the file "systemInfo.txt" which contains all platform' specific information.
The script gives also the opportunity to execute further commands
based on the wishes of the user.
Thanks again for your help.
Please, below you can find the script .
Elvis
Code:
#!/bin/sh
COMMANDS=""
OS_TYPE='unknown'
file_name='systemInfo.txt'
OS_TYPE=`uname`
getCommandsSpecificOS(){
AIX_COMMANDS[0]="hostname"
AIX_COMMANDS[1]="uname -a"
AIX_COMMANDS[2]="ulimit -a"
AIX_COMMANDS[3]="smtctl"
AIX_COMMANDS[4]="swap -l"
AIX_COMMANDS[5]="/etc/prtconf"
AIX_COMMANDS[6]="oslevel -s"
AIX_COMMANDS[7]="lparstat -i"
AIX_COMMANDS[8]="lscfg -vp | grep -ip proc | grep "PROC""
AIX_COMMANDS[9]="mpstat"
SunOS_COMMANDS[0]="hostname"
SunOS_COMMANDS[1]="uname -a"
SunOS_COMMANDS[2]="ulimit -a"
SunOS_COMMANDS[3]='/usr/platform/`uname -i`/sbin/prtdiag'
SunOS_COMMANDS[4]="/usr/sbin/psrinfo -pv"
SunOS_COMMANDS[5]="/etc/prtconf"
SunOS_COMMANDS[6]="cat /etc/release"
SunOS_COMMANDS[7]="swap -l"
SunOS_COMMANDS[8]="zoneadm list -vi"
Linux_COMMANDS[0]="hostname"
Linux_COMMANDS[1]="uname -a"
Linux_COMMANDS[2]="ulimit -a"
Linux_COMMANDS[3]="cat /proc/cpuinfo"
Linux_COMMANDS[4]="cat /proc/meminfo"
Linux_COMMANDS[5]="cat /etc/redhat-release"
Linux_COMMANDS[6]="cat /proc/version"
Linux_COMMANDS[7]="nvidia-smi -q"
if [ $1 = "AIX" ]; then
COMMANDS=("${AIX_COMMANDS[@]}")
elif [ $1 = "SunOS" ]; then
COMMANDS=("${SunOS_COMMANDS[@]}")
elif [ $1 = "Linux" ]; then
COMMANDS=("${Linux_COMMANDS[@]}")
fi
}
checkStorageFile(){
if [ -s $1 ]; then
rm $1
fi
}
exitStatusDescription(){
if [ $1 -eq 127 ]; then
echo "$2: Command not found" >> $file_name
elif [ $1 -eq 126 ]; then
echo "$2: Command invoked cannot execute - Permission problem or command is not an executable" >> $file_name
cmd=`echo $2 | awk '{print $1}'`
path=`whereis $cmd | awk '{print $2}'`
echo "\"$path\" has the following permission: `ls -ltr $path | awk '{print $1}'`" >> $file_name
echo "----> \"$path\" has the following permission: `ls -ltr $path | awk '{print $1}'`"
fi
}
printOnFileRichCommandInformation(){
echo >> $file_name
echo >> $file_name
echo ************************************************************ >>$file_name
echo ************************************************************ >>$file_name
echo ************ Additional information for $1 ************ >> $file_name
echo ************************************************************ >>$file_name
}
executeCommands(){
COMMANDS=$1
len=${#COMMANDS[*]}
command=0
while [ $command -lt $len ]; do
echo >> $file_name
echo "************************************************************" >> $file_name
if [[ ${COMMANDS[$command]} == lpar* ]];
then
printOnFileRichCommandInformation "LPAR"
fi
if [[ ${COMMANDS[$command]} == nvidia* ]];
then
printOnFileRichCommandInformation "GPU NVIDIA"
fi
echo ************************************************************ >> $file_name
echo " ${COMMANDS[$command]}"
echo bash$ ${COMMANDS[$command]} >> $file_name
eval ${COMMANDS[$command]} >> $file_name
OUT=$?
if [ $OUT -ne 0 ]; then
exitStatusDescription "$OUT" "${COMMANDS[$command]}"
fi
command=$((command+1))
done
}
printHeadFormatInfo(){
echo
echo *****************************************************************************
echo "Gathering system information ........"
echo *********************************************************** > $file_name
echo ********* GETTING SYSTEM INFORMATION ********* >> $file_name
echo *********************************************************** >> $file_name
echo *********** OPERATING SYSTEM TYPE: $OS_TYPE ************** >> $file_name
echo "***** Date: `date` ******" >> $file_name
echo
}
execute(){
COMMANDS=$1
######################## AIX Operating System ###########################################
if [ "$OS_TYPE" = "AIX" ]; then
echo "Operating System: AIX "
echo "System Information from following commands: "
executeCommands "${COMMANDS}"
elif [ "$OS_TYPE" = "SunOS" ]; then
######################## SunOS Operating System ###########################################
echo "Operating System: SunOS"
echo "System Information from following commands: "
executeCommands "${COMMANDS}"
elif [ "$OS_TYPE" = "Linux" ]; then
######################## Gnu/Linux Operating System ###########################################
echo "Operating System: GNU/Linux"
echo "System Information from following commands: "
executeCommands "${COMMANDS}"
fi
}
executeFurtherCommand(){
set WISH= "y"
while [ "$WISH" != "n" ]
do
echo *****************************************************************************
echo "Do you wish to gather further information? <y or n>"
read WISH
if [ $WISH = "y" ] ; then
echo >> $file_name
echo "************************************************************" >> $file_name
echo "Please insert the command you would like to execute...."
read -p '$bash ' COMMAND
echo bash$ $COMMAND >> $file_name
eval $COMMAND >> $file_name
OUT=$?
if [ $OUT -ne 0 ]; then
exitStatusDescription "$OUT" "$COMMAND"
else
echo "......command \"$COMMAND\" executed successfully!"
fi
fi
if [ "$WISH" != "n" ] && [ "$WISH" != "y" ] ; then
echo "your choice $WISH is incorrect"
fi
done
}
printBottomFormatInfo(){
echo
echo "........these information are stored on `pwd`/$1"
echo *****************************************************************************
}
###################################################################################################
checkStorageFile "$file_name"
printHeadFormatInfo
getCommandsSpecificOS $OS_TYPE
execute "${COMMANDS}"
printBottomFormatInfo "$file_name"
executeFurtherCommand
echo >> $file_name
echo >> $file_name
echo "************************************************************" >> $file_name
echo
Note that the shell you get may not have functions, either.
Instead of arrays, how about strings?
Code:
AIX_COMMANDS='hostname
uname -a
ulimit -a
smctl
swap -l
/etc/prtconf
oslevel –s
lparstat –i
lscfg -vp | grep -ip proc | grep "PROC"
mpstat'
OLDIFS="$IFS"
# Split on newlines and only newlines
IFS="
"
for X in $AIX_COMMANDS
do
echo "Got command $X"
done
IFS="$OLDIFS"
#include<stdio.h>
int main{
char *fl;
fl=(char*)malloc(150);
strcat(fl,"/tmp/OV/");
printf("\nInside fl--->%s\n",fl);
return 0;
}
I wrote a simple program as above. I got the error
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
Please help me out ! I am... (4 Replies)
Hi,
I'm trying to solve an assignement on school where we are supposed to synchronize two threads and write out their ID every other time.
I've written down the code for the two threadFunctions which is associated with two threads created in the main function.
What I'm trying to achieve... (5 Replies)
I have written the following shell script for submitting check to nagios .It was working fine a few hours ago.I don remember what changes i made and its giving integer expression expected error.
#!/bin/bash
#$PGREP ${SSHD}
if ]
then
echo "ssh down"
... (1 Reply)
CT=0
while read LINE
do
# Check to see if the LINE is non-empty, and has a <td> tag in it.
if
then
# Increase the TD counter by 1
CT=`echo "$CT+1"`
fi
done <test.htmthrows this error: ksh: test: argument expected
test.htm
<tr>
<td>text</td... (4 Replies)
I'm trying this script and I keep getting a 'fi' not expected error:
#!/bin/sh
#TD=0
CT=0
cat P7748 |while read LINE
do
# Check to see if the LINE is non-empty, and has a <td> tag in it.
if
# Increase the TD counter by 1
CT=`echo "$CT+1" |bc`
... (2 Replies)
Hi All
I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error.
#!/bin/ksh
#-------------------------------------------------------------------------
# File: ang_stdnld.ksh
#
# Desc: UNIX shell script to extract Store information.... (3 Replies)
Help please! :confused:
I have the following error with the following file and the emails are not arriving to the email, any idea please?
ERROR: ./launch_full_backup.sh: Syntax error at line 28 : `else' is not expected.
FECHA=`date +%d%m%y%H%M`... (2 Replies)
ive implemented getopt for the command line but have this problem,
#!/bin/sh
text=""
set -- getopt "t" etc .... #sets arguments
while :
do
case "$1" in #gets arguments
-t: shift; text="$1" ;;
shift
done
shift
if
then
echo "no text"
else
echo... (4 Replies)