This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Sunday, September 30, 2007
Download an XML feed with wget
C:\Documents and Settings\esoft\Desktop>wget www.xxxx.com/partnerfeeds/esofthub%20lists/esofthub%20xmllists.xml
--02:02:09-- http://www.xxxx.com/partnerfeeds/esofthub%20lists/esofthub%20xmllists.xml
=> `esofthub xmllists.xml'
Resolving www.xxxx.com... xx.1xx.x.2xx
Connecting to www.xxxx.com|xx.1xx.x.2xx|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 70,722,387 (67M) [text/xml]
100%[====================================>] 70,722,387 130.78K/s ETA 00:00
02:08:32 (182.75 KB/s) - `esofthub xmllists.xml' saved [70722387/70722387]
If you don't have wget, here's a couple site you can go to get it.
Download WGET for Windows
Download GNU WGET
Wednesday, September 26, 2007
Ping Multiple Workstations and Mail Results
# vi pinger.zsh
#!/bin/zsh
log=/tmp/log.`date '+%d%h%Y%H%M'`
echo >> $log
date >> $log
echo >> $log
for i in {1..30}
do
ping wkstn$i 2
if [ $? = 0 ]
then
echo wkstn$i up >> $log
else
echo wkstn$i down >> $log
fi
done
cat $log | mailx -s "Workstation Status: `basename $log`" groupalias@esofthub.com
#rm $log
:wq!
Friday, September 21, 2007
Use .htaccess to Deny Internet Protocol (IP) Address or Domain Name
The first two lines (deny statements) are indicative of what I did. By the way, I don't control the main configuration of the host (server), so I had to use this file.
# vi .htaccess
order allow,deny
allow from all
deny from xxx.xxx.xx.xxx
deny from xxx.xxx.xxx.xxx
deny from xx.xxx.xx.
deny from xxx.xx.
deny from xx.
:wq!
Here's a screenshot (so tags shows up on this Blogger post) with the tags:
Extra:
If you are trying to block IPs on the Blogger.com platform, see this post: How to block IPs on Blogger.com
Wednesday, September 19, 2007
Joining and Renaming Multiple Files Using a for loop
# sh
# for i in `ls *_num_*`
do
cat header $i footer > $i.$$
mv $i.$$ $i
echo $i done
done
Extra: For those that asked me how to rename files, the mv command is used to rename files in UNIX. In the example below, the esofthub filename will be renamed to esoft
e.g. # mv esofthub esoft
Monday, September 17, 2007
Delete Tabs, Newlines, Carriage Returns, or Spaces from a File
Note: I have included a screen shot of this task per the request of a commenter. This example in the jpeg deals with tabs and newlines.
Remove tabs
# more filename
esoft esoft esoft
esoft esoft esoft
# cat filename | tr -d space '\t'
esoftesoftesoft
esoftesoftesoft
# tr -d space '\t' < filename
Remove newlines
# cat filename | tr -d space '\n'
esoft esoft esoftesoft esoft esoft
Additional information:
Remove carriage returns
# cat filename | tr -d space '\r'
Remove spaces
# cat filename | tr -d space "space"
Friday, September 14, 2007
Evaluate NFS Statistical Information with nfsstat
The nfsstat command is used to show the statistical information of Network File System (NFS) and Remote Procedure Call (RPC). It is useful for showing NFS activity between the server and client. My box is down right now, so I won't be able to show you a run right now. But here are a few quick examples.
Show the nfs stats
# nfsstat
Evaluate NFS mount stats between server and the client
# nfsstat -m
Reinitialize the nfs stats
# nfsstat -z
Thursday, September 13, 2007
My SysAd Blog Reader Appreciation Shout
By the way, this is a terse "howto type" blog, so if you're looking for verbosity, that's another (or see man page) blog, so please checkout my technical blogroll :)
Respectfully,
Roy Wood
Try my favorite Free browser:
Get FireFox
My Favorite Links
Wednesday, September 12, 2007
Setup a nisplus Server and Populate its Tables
# cd /etc
# cp -p /etc/nsswitch.conf /etc/nsswitch.conf.sav
# cp -p /etc/nsswitch.nisplus /etc/nsswitch.conf
# domainname esofthub.com | tee /etc/defaultdomain
# domainname
esofthub.com
For safey reasons, use copies of the /etc files. Copy those /etc files to a staging area /var/nisfiles.
# cd /var
# mkdir nisfiles; chmod 755 nisfiles
# cd /etc
# cp -p hosts rpc services netmasks networks netgroup services protocols /var/nisfiles
# cd /var/nisfiles
Create empty files. It's recommended that you don't populate the contents of the local passwd and shadow files across the namespace.
# touch passwd shadow ipnodes timezone bootparams group aliases auto_home auto_master ethers
Bourne Shell
# PATH=$PATH:/usr/lib/nis; export PATH
C Shell
# setenv PATH ${PATH}:/usr/lib/nis
# csh
# setenv PATH ${PATH}:/usr/lib/nis
# nisserver -v -r -d esofthub.com
This script sets up this machine "esoft" as an NIS+
root master server for domain esofthub.com..
Domain name : esofthub.com.
NIS+ group : admin.esofthub.com.
NIS (YP) compatibility : OFF
Security level : 2=DES
Is this information correct? (type 'y' to accept, 'n' to change) y
This script will set up your machine as a root master server for
domain esofthub.com. without NIS compatibility at security level 2.
Use "nisclient -r" to restore your current network service environment.
Do you want to continue? (type 'y' to continue, 'n' to exit this script) y
setting up domain information "esofthub.com." ...
setting up switch information ...
switch configuration file already set to use NIS+.
killing process keyserv ...
restarting process keyserv ...
killing NIS and NIS+ processes ...
killing process ypbind ...
killing process rpc.nisd ...
killing process rpc.nispasswdd ...
killing process nis_cachemgr ...
stopping nscd ...
setup NIS_GROUP environment variable ...
rm /var/nis files ...
running nisinit ...
This machine is in the "esofthub.com." NIS+ domain.
Setting up root server ...
All done.
starting root server at security level 0 to create credentials...
running nissetup to create standard directories and tables ...
org_dir.esofthub.com. created
groups_dir.esofthub.com. created
passwd.org_dir.esofthub.com. created
group.org_dir.esofthub.com. created
auto_master.org_dir.esofthub.com. created
auto_home.org_dir.esofthub.com. created
bootparams.org_dir.esofthub.com. created
cred.org_dir.esofthub.com. created
ethers.org_dir.esofthub.com. created
hosts.org_dir.esofthub.com. created
ipnodes.org_dir.esofthub.com. created
mail_aliases.org_dir.esofthub.com. created
sendmailvars.org_dir.esofthub.com. created
netmasks.org_dir.esofthub.com. created
netgroup.org_dir.esofthub.com. created
networks.org_dir.esofthub.com. created
protocols.org_dir.esofthub.com. created
rpc.org_dir.esofthub.com. created
services.org_dir.esofthub.com. created
timezone.org_dir.esofthub.com. created
client_info.org_dir.esofthub.com. created
auth_attr.org_dir.esofthub.com. created
exec_attr.org_dir.esofthub.com. created
prof_attr.org_dir.esofthub.com. created
user_attr.org_dir.esofthub.com. created
audit_user.org_dir.esofthub.com. created
adding credential for esoft.esofthub.com...
Enter login password:
nisaddcred: WARNING: password differs from login password.
Retype password:
creating NIS+ administration group: admin.esofthub.com. ...
adding principal esoft.esofthub.com. to admin.esofthub.com. ...
updating the keys for directories ...
restarting NIS+ root master server at security level 2 ...
killing process rpc.nisd ...
restarting process rpc.nisd ...
starting NIS+ password daemon ...
starting NIS+ cache manager ...
modifying the /etc/init.d/rpc file ...
starting Name Service Cache Daemon nscd ...
This system is now configured as a root server for domain esofthub.com.
You can now populate the standard NIS+ tables by using the
nispopulate script or /usr/lib/nis/nisaddent command.
# nispopulate -v -F -p /var/nisfiles -d esofthub.com
NIS+ domain name : esofthub.com.
Directory Path : /var/nisfiles
Is this information correct? (type 'y' to accept, 'n' to change) y
This script will populate the standard NIS+ tables for domain
esofthub.com. from the files in /var/nisfiles:
auto_master auto_home ethers group hosts ipnodes networks passwd protocols services rpc netmasks bootparams netgroup aliases timezone auth_attr exec_attr prof_attr user_attr audit_user shadow
**WARNING: Interrupting this script after choosing to continue
may leave the tables only partially populated. This script does
not do any automatic recovery or cleanup.
Do you want to continue? (type 'y' to continue, 'n' to exit this script) y
auto_master.org_dir.esofthub.com. OK...
populating auto_master table from file /var/nisfiles/auto_master...
adding standard key-value table auto_master...
adding /var/nisfiles/auto_master to table auto_master.org_dir.esofthub.com.
0 entries added/updated
...
...
Credentials have been added for the entries in the
hosts and ipnodes and passwd table(s). Each entry was given a default
network password (also known as a Secure-RPC password).
This password is:
nisplus
Use this password when the nisclient script requests the
network password.
...
...
Check to see if nisplus was setup
# nisls
esofthub.com.:
org_dir
groups_dir
# niscat host.org_dir
localhost localhost 127.0.0.1
localhost loghost 127.0.0.1
esoft esoft 192.168.1.19
esoft mailhost 192.168.1.19
To remove NISPLUS
Visit this link: remove NIS+ from server
Monday, September 10, 2007
Forward Mail to a Different Account with .forward
All email will be forwarded to this email address, esoft@esofthubInTheWoods.com.
# echo "esoft@esofthubInTheWoods.com" > $HOME/.forward
Or
# cat > $HOME/.forward
esoft@esofthubInTheWoods.com
control ^d
Saturday, September 08, 2007
Output Strings in Lowercase -- UNIX
# cat uppercasefile | tr "[:upper:]" "[:lower:]"
this file's contents are in uppercase
but its output should be
lowercased
# tr "[:upper:]" "[:lower:]" < uppercasefile
this file's contents are in uppercase
but its output should be
lowercased
# cat uppercase | tr '[A-Z]' '[a-z]'
this file's contents are in uppercase
but its output should be
lowercased
# tr '[A-Z]' '[a-z]' < uppercasefile
this file's contents are in uppercase
but its output should be
lowercased
Output lowercase strings to file
# tr '[A-Z]' '[a-z]' < uppercasefile > outputfile_lower
# date | tr "[:upper:]" "[:lower:]"
sat sep 8 23:24:20 kst 2007
Friday, September 07, 2007
Traverse an Argument List using shift Command
# sh
The while loop
# set M Y S Y S A D B L O G
# while [ $# -gt 0 ]
> do
> echo $*
> shift
> done
M Y S Y S A D B L O G
Y S Y S A D B L O G
S Y S A D B L O G
Y S A D B L O G
S A D B L O G
A D B L O G
D B L O G
B L O G
L O G
O G
G
The for loop
# set M Y S Y S A D B L O G
# for i in $*
> do
> echo $*
> shift
> done
M Y S Y S A D B L O G
Y S Y S A D B L O G
S Y S A D B L O G
Y S A D B L O G
S A D B L O G
A D B L O G
D B L O G
B L O G
L O G
O G
G
Wednesday, September 05, 2007
Print a File in Landscape Mode via Command Line
# /usr/lib/lp/postscript/postprint -pland filename | lp
Tuesday, September 04, 2007
Set File or Directory Access Control List with setfacl
Replaces the entire ACL via man page
--setfacl -s user:esoft:rwx,user::rwx,group::rw-,mask:r--,other:--- testfile
or its octal equivalent
--setfacl -s user:esoft:7,user::7,group::6,mask:4,other:0 testfile
Before changing ACL
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rw-
group::r-- #effective:r--
mask:r--
other:r--
# ls -l testfile
-rw-r--r-- 1 root other 0 Sep 4 23:26 testfile
After changing ACL
# setfacl -s user:esoft:rwx,user::rwx,group::rw-,mask:r--,other:--- testfile
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rwx
user:esoft:rwx #effective:r--
group::rw- #effective:r--
mask:r--
other:---
# ls -l testfile
-rwxr-----+ 1 root other 0 Sep 4 23:27 testfile
Same as above but in octal
# rm testfile
# touch testfile
# ls -l testfile
-rw-r--r-- 1 root other 0 Sep 4 23:30 testfile
# setfacl -s user:esoft:7,user::7,group::6,mask:4,other:0 testfile
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rwx
user:esoft:rwx #effective:r--
group::rw- #effective:r--
mask:r--
other:---
# ls -l testfile
-rwxr-----+ 1 root other 0 Sep 4 23:32 testfile
#######################################
Change user and mask
# setfacl -m u:esoft:6,m:6 testfile
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rwx
user:esoft:rw- #effective:rw-
group::rw- #effective:rw-
mask:rw-
other:---
Change group and mask
# setfacl -m g:other:4,m:6 testfile
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rwx
user:esoft:rw- #effective:rw-
group::rw- #effective:rw-
group:other:r-- #effective:r--
mask:rw-
other:---
Delete ACL
# setfacl -d u:esoft:6 testfile
# getfacl testfile
# file: testfile
# owner: root
# group: other
user::rwx
group::rw- #effective:rw-
group:other:r-- #effective:r--
mask:rw-
other:---
Get ACL of testfile then set (apply) to testfile1
# getfacl testfile | setfacl -f - testfile1
Monday, September 03, 2007
Get the Access Control List on a File or Directory
On a file
# getfacl newcron
# file: newcron
# owner: esoft
# group: staff
user::rw-
group::r-- #effective:r--
mask:r--
other:r--
On a directory
# getfacl MyDir
# file: MyDir
# owner: root
# group: other
user::rwx
group::r-x #effective:r-x
mask:r-x
other:r-x