| Unix Admin scripts | General commands and utilities |
| Text processing | Networking |
| Filesystem scripts | System monitoring | Printing | Hardware |
#/bin/ksh
echo "This script will put the names of ten day old files in /tmp in /tmp/checkold.txt file"
find /tmp -size 0 -atime +10 -exec ls -l {} \; > /tmp/checkold.txt
find /tmp -size 0 -atime +10 -exec rm -f {} \;
---------
#!/bin/sh
# Script to find the big files on a disk.
# Defaults and temporary info.
# This script send the output to a default printer
DiskName=${1:?Disk name not supplied.}
TMPFILE=/tmp/$LOGNAME.$$.txt
SysName=`uname -n`
echo \
"Checking for large files on $SysName $DiskName. " \
"Output will be sent to default printer."
echo "\nNewer big files on $SysName $DiskName" >> $TMPFILE
find $DiskName -type f -mtime -3 -size +5000 -exec ls -ld {} \; \
2>/dev/null | sort -n -k 5.1,5 >> $TMPFILE
echo "\nOlder big files on $SysName $DiskName" >> $TMPFILE
find $DiskName -type f -mtime +3 -size +5000 -exec ls -ld {} \; \
2>/dev/null | sort -n -k 5.1,5 >> $TMPFILE
#change the following line if you want to put output to a file
#or anything.
lp -onb -olandscape $TMPFILE
rm $TMPFILE
# End of script
#!/bin/ksh echo * | wc -w
#!/bin/ksh
#This script will return the total disk space in system.
df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/10000
00}'
#!/bin/ksh
#This script tells total used space in a system
df | awk 'BEGIN {tot=0} {tot=tot+$4} END {print (tot*512)/1000000}'
#!/bin/ksh
#This script searchs the file passed as first argument to this command line and
#prints total number found
grep $1 filename | awk 'BEGIN {tot=0} {tot=tot+$1} END {print (tot)}'
#!/bin/ksh
find / -name core -group mycomp -print -exec rm -f {} \; >> mycompcore
The easiest way to set the umask for a user when they ftp files to a server is to write a wrapper program as follows:
#!/bin/sh umask xxx <- insert choice here /usr/sbin/in.ftpdsave it as ftpwrap.sh (or anything you like). Along with your TCP wrappers the line in inetd.conf looks something like this:
ftp stream tcp nowait root /usr/sbin/tcpd ftpwrap.sh
Usually when a shell scripts that works from command line but not from crontab file,it means that crontab is not using the correct shell to execute this script. That means that the first line in script #!/usr/bin/ksh is incorrect and ksh is not in /usr/bin or something else to that extent.
#!/bin/sh ## This script monitors a system named dxi4. ## Date created : May 15 1997 rm status.dxi4 echo '' > status.dxi4 echo ' ****************************************************' >> status.d xi4 echo ' *************** LATEST DXI4 STATUS *****************' >> status.d xi4 echo ' ****************************************************' >> status.d xi4 echo '' >> status.dxi4 echo ' *************** DATE *****************' >> status.d xi4 echo '' >> status.dxi4 date >> status.dxi4 echo '' >> status.dxi4 banner Netstat >> status.dxi4 echo '' >> status.dxi4 netstat -m >> status.dxi4 echo '' >> status.dxi4 banner Fax >> status.dxi4 echo '' >> status.dxi4 fxstat >> status.dxi4 echo '' >> status.dxi4 echo ' ****************************************************' >> status.d xi4 banner Disk >> status.dxi4 echo '' >> status.dxi4 df >> status.dxi4 echo '' >> status.dxi4 echo ' *******************Virtual Memory ******************' >> status.d xi4 sar >> status.dxi4 banner Paging >> status.dxi4 sar -p >> status.dxi4 echo ' *******************free virtual memory *************' >> status.d xi4 sar -r >> status.dxi4 echo ' ****************************************************' >> status.d xi4 echo ' ******************* Processes *********************' >> status.d xi4 echo ' ************* All rtm processes ****************' >> status.d xi4 echo '' >> status.dxi4 ps -ef | grep 'rtm' >> status.dxi4 echo '' >> status.dxi4 echo ' ************* All dbsid processes ****************' >> status.d xi4 echo ' **Check that synchronization is only one per site **' >> status.d xi4 echo '' >> status.dxi4 ps -ef | grep 'dbsid' >> status.dxi4 echo '' >> status.dxi4 echo ' ************* All pws processes ****************' >> status.d xi4 echo '' >> status.dxi4 ps -ef | grep 'pws' >> status.dxi4 echo '' >> status.dxi4 echo ' ************* All sql processes ****************' >> status.d xi4 echo '' >> status.dxi4 ps -ef | grep 'sql' >> status.dxi4 echo '' >> status.dxi4 echo ' ****************************************************' >> status.d xi4 echo '' >> status.dxi4 echo ' ****************** System Error Report *************' >> status.d xi4 echo '' >> status.dxi4 tail -500 /usr/adm/messages >> status.dxi4 echo '' >> status.dxi4 echo ' ********************* Top Will now run **************************' >> status.dxi4 more status.dxi4 top
This
includes general commands shell scripts.
Alias input from user.
$< will read a line of user input and return it.
alias abc 'echo -n lynx http://www.;lynx http://www.$<'
The echo command causes the partial command to be printed as a prompt, and
then the user response is substituted into the command with $<.
All the text processing commands+scripts
Some user's don't like to use vi the default editor with all unix systems.
You can get a user friendly editor called pico which is also embedded into
pine e-mail system is available at
http://www.washington.edu/pine/overview/availability.html
To change the case (upper to lower or viceverse) of a large number of
files. You can use this following script.
#to change uppercase filenames to lowercase #!/bin/sh if [ $# -eq 0 ] ; then echo Usage: $0 Files exit 0 fi for f in $* ; do g=`echo $f | tr "[A-Z]" "[a-z]"` echo mv -i $f $g mv -i $f $g done
Networking commands and Scripts.
All tcp/ip commands, scripts, etc here.
back to top
Back to main page
Other problems and solutions
Kernel configuration trouble.
If mk_kernel -s system is giving you error after you have installed patches or have done similar installation. That usually means that JFS got messed up by the patches; recompiling the kernel would give the same error (but different unsatisfied symbols). To see the depencency and conflicts you have in kernel do
swconfig \*Then resolve those conflicts and recompile the kernel.
Some commands like find which if are run recursively can bring down system virually to a halt state. Glance utility that is HP-UX product can see that which find command seems to be hogging most of the cpu time, spending most of its time in stat() and lstat() calls. Disc, memory and network are idle at the time.
find is looking through every directory in the entire system, a very, very bad thing to do.
Since the task involves a bit of computing, and a bit of disk directory reading, it
will hog resources proportional to the number of files on thye system disks.
When disks were 250-500 megs, one or two users and the Unix box had perhaps
10-20,000 files, find / was a possible method to locate a file.
Today, it is considered very bad practice and most sysadmins will wrap the find command with a test to
prevent this bad practice.
As a client, you first need to identify the IP address of the DNS
server you with to use. Let's call that address 10.0.0.1. Then:
create /etc/resolv.conf to contain at a minimum:
domain spinet.gov.sp nameserver 10.0.0.1
edit /etc/nsswitch.conf and change the "hosts" line to include dns. For example, if it did say "hosts: files" then change it to "hosts: files dns" . At this point any *newly created* processess will be using DNS. But the daemons started before you made these changes (such as sendmail) will not see the change to nsswitch.conf until they are restarted. If this is important, then either restart the affected daemons or just reboot the machine. But make sure that DNS lookups work correctly before rebooting or you may have a very difficult time getting the machine to come back up again.
| Fundamentals of Unix | Unix commands | User Accounts | Shell Programming |
| File Systems | Networking | Backups | Security |
| Installing software | Installing Hardware | Performance and Tuning | Some Useful Scripts |
These scripts and other information was collected from usenet newsgroups pertaining
to unix like comp.unix.shell and comp.unix.admin. Your suggestions and comments are welcome. Please e-mail me
Copyright reserved with Sandeep S Bajwa.