Clearing an AIX Print Queue

[problem]

You have jobs stuck in the print queue. You want to clear the queues and remove all jobs.

[/problem]

[solution]

You have to stop all processes and remove the files from spooling directories.

Probably worth taking a backup of these files first. 🙂 All at own risk.

[/solution]

[example]

1.


stopsrc -cs qdaemon # bring down qdaemon and clear qdforks.
stopsrc -s lpd

2.


rm /etc/qconfig.bin # compiled /etc/qconfig

3.


rm /var/spool/lpd/qdir/* # queue requests; JDF

4.


rm /var/spool/lpd/stat/* # info on status of devices

5.


rm /var/spool/lpd/pio/msg* # error message files.

6.


rm /var/spool/qdaemon # temp copies of queue jobs

7.


rm /var/spool/lpd/* # temp copies of remote jobs

8.


ps -ef | grep pio # kill any of these processes; look for piobe, pioformat, pioout

9.


ps -ef | grep qd # kill any of these processes; look for qdforks.

10.


startsrc -s qdaemon # restarting qdaemon
startsrc -s lpd # restarting lpd

11.


lssrc -s qdaemon #look for active
ps -ef | grep qdaemon
lssrc -s lpd # look for active
ps -ef | grep lpd

12.


ps -ef | grep srcmstr # if there are 2 running, kill -9 one of them with higher PID.

13.

As a last resort – reboot

[/example]

[reference]

[tags], Unix Coding School[/tags]

[/reference]

DNS, Sendmail and Building Linux

[problem]

Have been aware of DNS and sendmail for over 10 years, but never really dabbled.

[/problem]

[solution]

Hit a lot of issues, mainly with dodgy clients – like outlook (ended up moving over completely to mozilla’s thunderbird email client!). Also with port forwarding and firewall, default routes, etc.

To set it all up these were my steps:

1) Build RH Linux server with fedora core 4 (5 is out now too I think).
2) Ensure BIND was installed. yum is your friend! 🙂 Do yum –help as root.
3) Edit /etc/named.conf – add my zone file. Always make a bu: cp -i /etc/named.conf /etc/named.conf.$(date +%j)
4) Copied localdomain.zone to puterpet.zone # this domain is retired now. 🙂
5) Modified puterpet.zone to include my info: SOA (start of authority) – in my case I said zion.puterpet.com as this then relates to the ip of broadband router. Bit backward in logic, specify your DNS server with a name registered in your DNS server! 🙂 Then I created an A record and NS for zion; CNAME for www to zion and CNAME for mail; lastly an MX record for mail. I’ll happily supply my zone file if someone wants a peek. 🙂
6) Register domain name with www.domaincentral.com.au – $12.50 a year! 🙂 Give it the ip of my DNS server – which is actually the broadband router, with port 53 forwarded to my RH Linux box. domaincentral have been great (I’ve now got 3 domains with them). www.puterpet.com – this one www.techie-blogs.com and darlingranges.com (still setting this up).
7) Setup port forwarding on broadband router, then fire up named and it was all good. Setup up virtual hosts (www.puterpet.com and mail.puterpet.com) in that domain. Now can setup any mail account or host in that domain, it is just beautiful! 🙂
8) Installed/updated sendmail. Especially like watching sendmail’s incoming and outgoing messages. 🙂
9) Edit /etc/mail/sendmail.mc – which is a macro config file that gets fed into m4 (macro language). Had to update m4, etc as kept breaking during conversion.
10) Edited various other files under /etc/mail – such as relay_domains (allow email from puterpet.com, etc); aliases …
12) Installed dovecot – which services POP and SMTP requests.
13) Created some accounts to handle mail – sales; enquiries, etc.
14) Modified my apache confs to handle and redirectmatch to new domain.

[/solution]

[example]

[/example]

[reference]

[tags]sendmail, DNS, POP, SMTP, Red Hat Linux, Unix Coding School[/tags]

[/reference]

AIX ODM removing device

[problem]

Someone removes a tty, printer, etc by doing rm /dev/lp3.

Then you cannot recreate the device, as system returns “already defined at that location”.

[/problem]

[solution]

You can try to recreate the device with mknod, but need the major/minor numbers.

Then do rmdev -l lp1 -d.

To get major, minor numbers you need to query the ODM.

[/solution]

[example]


odmget -q "value3=lp1" CuDvDr

Should return something like:

CuDvDr:

resoure=”devno”
value1=”15″
value2=”2″
value3=”lp1″

The major number is 15 and minor 2.

Therefore mknod /dev/lp1 c 15 2 creates the device again.

Then rmdev -l /dev/lp1 -d should remove it cleanly.

In extreme cases, where this still does not remove it, you may have to manipulate
the ODM directly. * Proceed with caution *

Backup

cd /etc/objrepos
cp -i CuDv CuDv.$(date +%j)
cp -i CuAt CuAt.$(date +%j)
cp -i CuDvDr CuDvDr.$(date +%j)

Remove ODM entries

odmdelete -q "name=lp1" CuAt
odmdelete -q "name=lp1" CuDv
odmdelete -q "value=lp1" CuDvDr
synclvodm rootvg # resync odm

Reboot if necessary.

[/example]

[reference]

[tags]AIX ODM, odmdelete, synclvodm, Unix Coding School[/tags]

[/reference]

who command 5 ways

[problem]

You want to know who is on the system. Or which userid you are using.
What runlevel you are at – or when the system was booted.

All doable with who.

[/problem]

[solution]

See the example and reference tabs, to see 5 ways to run who, showing different things about the system and users.

[/solution]

[example]

1. Basic


[marcus@bagend puterpet]$ who
marcus pts/1 Sep 19 16:07 (10.0.0.8)
marcus pts/3 Sep 22 17:46 (10.0.0.8)

2. With Heading and Idle time dot means currently active.


[marcus@bagend puterpet]$ who -Hu
NAME LINE TIME IDLE PID COMMENT
marcus pts/1 Sep 19 16:07 ? 29984 (10.0.0.8)
marcus pts/3 Sep 22 17:46 . 29566 (10.0.0.8)

3. Show who I am in the current shell and where I came from.


[marcus@bagend puterpet]$ who am i
marcus pts/3 Sep 22 17:46 (10.0.0.8)

4. Show the current run level Shows boot time and last runlevel too.


[marcus@bagend puterpet]$ who -r
run-level 5 Sep 9 10:47 last=S

5. Show last boot time


[marcus@bagend puterpet]$ who -b
system boot Sep 9 10:47

[/example]

[reference]

[tags]who command, Unix Coding School[/tags]

[/reference]

List files 12 ways

[problem]

You want to list files under UNIX! 🙂 Here I show 12 different ways to do it.

[/problem]

[solution]

See the example and reference tabs.

[/solution]

[example]

1. Basic


[marcus@bagend Perl_Bin]$ ls
d-dump-tst.pl demo-ldap-entry2.pl demo-ldap-entry5.pl ldap-to-sql.pm
logcam.pm showstat.pl
demo-ldap-entry1.pl demo-ldap-entry3.pl demo-ldap-entry6.pl listenport.pl perl_eval_pattern.pl showtime.pl
demo-ldap-entry1.pm demo-ldap-entry4.pl ldap-to-sql.pl logcam.pl
scanport.pl

2. Long


[marcus@bagend Perl_Bin]$ ls -l
total 68
-rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl
...
-rwx------ 1 marcus adm 151 Feb 5 2006 showtime.pl

2. Hidden files


[marcus@bagend Perl_Bin]$ ls -la
total 76
drwxr-xr-x 2 marcus adm 4096 Aug 15 04:53 .
drwx------ 29 marcus adm 4096 Sep 23 11:47 ..
-rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl
...
-rwx------ 1 marcus adm 151 Feb 5 2006 showtime.pl

3. Sort by last modified


[marcus@bagend Perl_Bin]$ ls -lt
total 76
-rwxr--r-- 1 marcus adm 286 Aug 15 04:53 perl_eval_pattern.pl
-rw-r--r-- 1 marcus adm 210 Apr 30 08:07 logcam.pm
-rwxr--r-- 1 marcus adm 3483 Feb 5 2006 logcam.pl
...
-rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl

4. Sort by last modified – reverse


[marcus@bagend Perl_Bin]$ ls -ltr
total 76
-rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl
...
-rwxr--r-- 1 marcus adm 3483 Feb 5 2006 logcam.pl
-rw-r--r-- 1 marcus adm 210 Apr 30 08:07 logcam.pm
-rwxr--r-- 1 marcus adm 286 Aug 15 04:53 perl_eval_pattern.pl

5. Show hidden characters in file name


[marcus@bagend Perl_Bin]$ ls -ld *test*
-rw-r--r-- 1 marcus adm 5 Sep 23 11:59 ???testfile1
[marcus@bagend Perl_Bin]$ ls -lb *test*
-rw-r--r-- 1 marcus adm 5 Sep 23 11:59 bbbtestfile1

6. Show a digest of directories With asterix for executable and slash for directory, etc.


[marcus@bagend Perl_Bin]$ ls -aF
./ demo-ldap-entry1.pl* demo-ldap-entry3.pl* demo-ldap-entry6.pl*
listenport.pl* perl_eval_pattern.pl* showtime.pl*
../ demo-ldap-entry1.pm demo-ldap-entry4.pl* ldap-to-sql.pl*
logcam.pl* scanport.pl*
d-dump-tst.pl* demo-ldap-entry2.pl* demo-ldap-entry5.pl* ldap-to-sql.pm
logcam.pm showstat.pl*

7. Do a recursive listing

[marcus@bagend Perl_Bin]$ ls -lR
.:
total 76
-rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl
...
-rw-r--r-- 1 marcus adm 5 Sep 23 11:59 ???testfile1

./test1:
total 4
drwxr-xr-x 2 marcus adm 4096 Sep 23 12:01 test2

./test1/test2:
total 0
-rw-r--r-- 1 marcus adm 0 Sep 23 12:01 showit

8. List the directory not its contents.


[marcus@bagend marcus]$ ls -ld Perl_Bin
drwxr-xr-x 3 marcus adm 4096 Sep 23 12:01 Perl_Bin

9. Digest the listing


[marcus@bagend Perl_Bin]$ ls -m
d-dump-tst.pl, demo-ldap-entry1.pl, demo-ldap-entry1.pm, demo-ldap-entry2.pl, demo-ldap-entry3.pl, demo-ldap-entry4.pl, demo-ldap-entry5.pl,
demo-ldap-entry6.pl, ldap-to-sql.pl, ldap-to-sql.pm, listenport.pl, logcam.pl, logcam.pm, perl_eval_pattern.pl, scanport.pl, showstat.pl,
showtime.pl, test1, ???testfile1

10. Include the inode – useful for then doing find . -inum #### – to remove, etc


[marcus@bagend Perl_Bin]$ ls -li
total 76
647846 -rwxr--r-- 1 marcus adm 335 Sep 12 2005 d-dump-tst.pl
...
648063 -rw-r--r-- 1 marcus adm 5 Sep 23 11:59 ???testfile1

11. Force ls to produce one column


[marcus@bagend Perl_Bin]$ ls -1
d-dump-tst.pl
...

12. Show file modified time in seconds Okay I cheated here – it is Perl! 🙂 But hey it’s my blog!! 😉


[marcus@bagend Perl_Bin]$ perl -e
'print(localtime((stat($ARGV[0]))[9])."n");' mytestfile
Sat Sep 23 12:50:03 2006

[/example]

[reference]

[tags]Listing files, Unix Coding School[/tags]

[/reference]

Permissions extension setfacl

[problem]

You want to allow access to files or directories, without giving exclusive use of a given group, user, etc.

[/problem]

[solution]

Use setfacl. 🙂 See the example and reference tabs.

[/solution]

[example]


setfacl -m user:USERID:rw- filename

getfacl filename

Can also do this: getfacl filename1 | setfacl -f – filename

Performing an ls -ld filename, will show a plus in the permission column.

[/example]

[reference]

[tags]setfacl, Unix Coding School[/tags]

[/reference]

Linux dircmp – directory compare

[problem]

I wanted to run a dircmp with the -d option, to show all files that are different.

Plus display those differences.

Linux replied – command not found! 🙂

[/problem]

[solution]

Just diff the directories, with the -d flag. See the example and reference tabs for more info.

[/solution]

[example]


diff -d dir1 dir2

[/example]

[reference]

[tags]UNIX, Linux, Dircmp, Unix Coding School[/tags]

[/reference]

Redundant key strokes

[problem]

Carrying on with my lazy steps, there are bits of code used with UNIX commands, which are completely redundant.

[/problem]

[solution]

Save yourself some key strokes, remember these examples. Or come back to unix.coding-school.com and check them out again. 🙂

[/solution]

[example]


chmod a+r filename

The “a” is redundant – if you just do a “+r” – all is implied.


ls -l | awk ' $4 > 1000 { print $0 } '

In awk printing $0 is default action.


find . -type f -print

With find default action is to print.


echo a b c | tr '[abcdef]' '[ABCDEF]'

Use a range: echo a b c | tr ‘[a-z]’ ‘[A-Z]’

In vi use ZZ instead of :wq 🙂

Only 2 chars less (including the shift) – but also just your little finger, instead of a hand span. 🙂

[/example]

[reference]

[tags]Redundant key strokes, UNIX shortcuts, Unix Coding School[/tags]

[/reference]

Restarting Linux services boot time

[problem]

Every time you reboot your Linux Box – web server, samba server, etc is down.

[/problem]

[solution]

Use chkconfig. See the example tab and then reference tab for man page.

[/solution]

[example]

Show all services


chkconfig --list

List just httpd


chkconfig --list httpd

Change restart settings so web server starts at run level 5.
(do a runlevel to see normal level – most likely 5).


chkconfig --levels 5 httpd on

[/example]

[reference]

[tags]chkconfig, Linux reboot, Linux services, Linux restarts, Unix Coding School[/tags]

[/reference]

Lazy tip – wrong password

[problem]

You start typing your password in UNIX, then realize – hold on that ain’t right.

Sometimes your control c it – other times just hit enter and do it again.

There is a quicker way. 🙂

[/problem]

[solution]

When your sat at that password: prompt and lord only knows what you’ve typed. No problem – just do one control u and all is right with the world again. 🙂

I only know from the billion odd times I’ve done it too! 😉 That equates to many wasted hours, this lazy tip will save you – over time.

[/solution]

[example]

Nothing to see here, check out the solution tab.

[/example]

[reference]

[tags]UNIX Lazy tip, UNIX passwords, Unix Coding School[/tags]

[/reference]