Академический Документы
Профессиональный Документы
Культура Документы
http://www.sikh-history.com/computers/unix/scripts.html
Unix admin Scripts and commands. All the scripts and commands concerning system administration are in this section.
Filesystem scripts System monitoring Printing Hardware
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
1 of 6
4/9/2014 6:58 AM
http://www.sikh-history.com/computers/unix/scripts.html
This command will find the core files with group name mycomp and delete them while also writing the name of deleted file in mycompcore.
#!/bin/ksh find / -name core -group mycomp -print -exec rm -f {} \; >> mycompcore
save 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
2 of 6
4/9/2014 6:58 AM
http://www.sikh-history.com/computers/unix/scripts.html
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. Sample system monitoring Script
#!/bin/sh ## This script monitors a system named dxi4. ## Date created : May 15 1997 rm status.dxi4 echo '' > status.dxi4 echo ' ****************************************************' xi4 echo ' *************** LATEST DXI4 STATUS *****************' xi4 echo ' ****************************************************' xi4 echo '' >> status.dxi4 echo ' *************** DATE *****************' xi4 echo '' >> status.dxi4 date >> status.dxi4 echo '' >> status.dxi4
>> status.d
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 *************' xi4 sar -r >> status.dxi4 echo ' ****************************************************' xi4 echo ' ******************* Processes *********************' xi4 echo ' ************* All rtm processes ****************' xi4 echo '' >> status.dxi4 ps -ef | grep 'rtm' >> status.dxi4
>> status.d
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
3 of 6
4/9/2014 6:58 AM
http://www.sikh-history.com/computers/unix/scripts.html
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
General Shell commands and scripts 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 $<.
4 of 6
4/9/2014 6:58 AM
http://www.sikh-history.com/computers/unix/scripts.html
Change file names to upper case 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
Then resolve those conflicts and recompile the kernel. System hog problems 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
5 of 6
4/9/2014 6:58 AM
http://www.sikh-history.com/computers/unix/scripts.html
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. To setup DNS As a client or as a server? 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
test with nslookup to ensure that lookups will work correctly 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. back to top Back to main page Fundamentals of Unix Unix commands File Systems Installing software Networking User Accounts Backups Shell Programming Security
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.
6 of 6
4/9/2014 6:58 AM