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]

YUM fails with 404

[problem]

If you (like me) was well keen, to get your shiny new fedora core 5 system up and running. Then you run yum and think, hang on that ain’t right – 404. Linux is better than this!! 🙁

[/problem]

[solution]

Don’t bother searching the news groups, for posts that go nowhere (like I did for close on 2 hours – that I’ll never get back!! 🙂 ), here is the answer –

www.fedorafaq.org Do a search for yum – follow the prompts and you’re in.

[/solution]

[example]

Nothing to see here, check out the solution tab.

[/example]

[reference]

[tags]Linux YUM, YUM fails, YUM problems, Unix Coding School[/tags]

[/reference]

Linux iptables blocking IP address

[problem]

You do a netstat -an and see a raft of connections to your apache host, coming in at 10 – 20 a second.

It shows ::ffff:10.0.0.10:80 ::ffff:212.248.1.1:1403 in netstat output. These are IPV6 connections AFAIK.

Also you see ::1 – – [DD/MMM… in apache log. Restarting apache does nothing, the connections just reappear.

[/problem]

[solution]

You need to block all connections from this IP address using iptables. See example tab.

[/solution]

[example]


cp -i /etc/sysconfig/iptabes /etc/sysconfig/iptables.$(date +%j).bu
vi /etc/sysconfig/iptables

Add a line like the one below:

#block
-A INPUT -s 212.248.225.12 -j DROP

Then restart iptables like this: /etc/init.d/iptables restart as root.

Finally check your rules like this: /etc/init.d/iptables status as root.

[/example]

[reference]

[tags]Linux Security, Linux iptables, Fedora Core iptables, Linux Firewall, Unix Coding School[/tags]

[/reference]