Help New to Scripting

I need to write a script to check the server before hand if all the requirements are correct.

df -h
grep processor /proc/cpuinfo
free (memory)
id
/fisc/uts/bin/sudo zksh

so i need a script wherein if i run it the following commands should execute and the output should be appended to a txt file.

Thank You

You have all the commands with you :slight_smile:

I think you will just need the sample! You can get it from anywhere either a text or online :slight_smile:

Thank You for your reply. Can you provide me with a sample script or the link where I can find it. I am new to scripting. I never wrote a script .

Ah, thats too easy :slight_smile:

May be these should work for you...

BOOK
EXERCISES

#!/bin/ksh -x
set -x
chmod 775 intial_validation.ksh
########################################################################################
#FileSystem
########################################################################################
echo "----------------------------------------------------------------------------------" >> intial_log.txt
echo "--------------------------FileSystem----------------------------------------------" >> intial_log.txt
echo "----------------------------------------------------------------------------------" >> intial_log.txt
df -h >> intial_log.txt
########################################################################################
#Processors
########################################################################################
echo "----------------------------------------------------------------------------------" >> intial_log.txt
echo "--------------------------Processor----------------------------------------------" >> intial_log.txt
echo "----------------------------------------------------------------------------------" >> intial_log.txt
grep processor /proc/cpuinfo >> intial_log.txt
########################################################################################
#Memory
########################################################################################
echo "----------------------------------------------------------------------------------" >> intial_log.txt
echo "--------------------------Memomry----------------------------------------------" >> intial_log.txt
echo "----------------------------------------------------------------------------------" >> intial_log.txt
free >> intial_config.txt
########################################################################################
#semaphores
########################################################################################
echo "----------------------------------------------------------------------------------" >> intial_log.txt
echo "--------------------------Semaphores----------------------------------------------" >> intial_log.txt
echo "----------------------------------------------------------------------------------" >> intial_log.txt
cat /proc/sys/kernel/msgmni >> intial_log.txt
cat /proc/sys/kernel/shmmni >> intial_log.txt
cat /proc/sys/kernel/shmall >> intial_log.txt
cat /proc/sys/kernel/shmmax >> intial_log.txt
cat /proc/sys/kernel/sem >> intial_log.txt
cat /proc/sys/fs/file-max >> intial_log.txt
cat /proc/sys/net/ipv4/tcp_keepalive_time >> intial_log.txt
########################################################################################
#Sudo access and Groups
########################################################################################
echo "----------------------------------------------------------------------------------" >> intial_log.txt
echo "--------------------------Sudo Access/Groups----------------------------------------------" >> intial_log.txt
echo "----------------------------------------------------------------------------------" >> intial_log.txt
/fisc/uts/bin/sudo zksh
id >> intial.txt
exit
########################################################################################
#Dos2unix
########################################################################################
echo " Dos2Unix (To Exit hit Ctrl C)"
dos2unix

Will this script work or should i make any changes?

1 Like

A hint:

ch:/home/vbe $ echo "MSGMNI = " $(cat /proc/sys/kernel/msgmni)
MSGMNI =  16

Now using my hint, you could write a script on that principle, where you redirect the script output to a file ( and not line after line...) or if you want to see things on the display at the same time its possible by using the tee command...
What is zksh? (your sudo line...)

Thank you for your reply. But could you please give me an example on where to put the code and how do i redirect the output of the script to a file from within the script. yes zksh is for sudo
Thank you in advance

#!/bin/ksh -x
:
#@(#)yourscriptname: describe what its for
# now when you type what /path/yourscript you will get the description...
set -x
.
.
.
#semaphores
########################################################################################
echo "----------------------------------------------------------------------------------"
echo "--------------------------Semaphores----------------------------------------------"
echo "----------------------------------------------------------------------------------"
echo "msgmni = " $(cat /proc/sys/kernel/msgmni)
echo "shmmni = "$(cat /proc/sys/kernel/shmmni)
echo "shmall = "$(cat /proc/sys/kernel/shmall)
echo "shmmax = "$(cat /proc/sys/kernel/shmmax)
echo "sem = "$(cat /proc/sys/kernel/sem)
echo "file-max = "$(cat /proc/sys/fs/file-max)
echo "tcp_keepalive_time = "$(cat /proc/sys/net/ipv4/tcp_keepalive_time)
.
.
.
~

when you run your script:

[code]
/path/yourscript >output.txt

As I said you could use tee command to see STDOUT and redirect to a file...

You still did not say what was zksh... ( a script ?)