Linux Tips



General Tips

Changing Multiple Filenames
Use the following command to change characters in all the files in a directory:
for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done



Recursive File Search
Need to find a string within some code? Use this to search through all files, in all folders, from the current directory:
find . -exec grep -i "string" {} /dev/null ;



Simple DHCP config file:
shared-network domain.com {
subnet a.b.c.d netmask 255.255.255.0 {
range a.b.c.1 a.b.c.254;
option broadcast-address a.b.c.255;
server-identifier server.domain.com;
option routers a.b.c.d;
option domain-name "domain.com";
option domain-name-servers a.b.c.d;
option netbios-name-servers a.b.c.d;
option netbios-node-type 8;
default-lease-time 43200;
max-lease-time 43200;
}
}



The Setup Utility
There is a little-known utility called setup (/usr/sbin/setup) in RedHat 6.x that allows you to turn on/off system services at boot-time; configure your soundcard, keyboard, and mouse; and even configure your video card and monitor for X-Windows. Timezone and Authentication configurations are there as well.



Useful smb options:
valid users = {user}
create mask = 0744
force user = {user}
force group = {user}
force create mode = 775
force directory mode = 775



Global Replace in vi:
:%s/from/to/g

%s/: All lines in the file;
from/: RegEx string from;
to/: Replacement string;
g: All matches in each line.



Using BitchX to auto-op a user:
Type the following from a BitchX terminal:
/adduser nick #channel friend,i_ops
/cset * aop on
/set aop on
/save


Networking Tips

Add motd on telnet:
in /etc/services:
motd {portnum}/tcp
in /etc/inetd.conf:
motd stream tcp nowait root {add tcpwrapper here} /usr/games/fortune



Allowing relaying in sendmail:
Add to sendmail.mc:
FEATURE(relay_hosts_only)
MAILER(local)
then do: m4 /etc/sendmail.mc > /etc/sendmail.cf

Add to /etc/mail/access:
{host} relay
then do: make all



Sendmail: hostname does not exist
Did you set up relaying in sendmail only to have mail returned with an error like: hostname must exist? The problem is that your server may not have a DNS entry that can be found with a reverse lookup. To solve this, look for a Dj option in your /etc/sendmail.cf file. Uncomment the option and add the domain (or valid server) for your network, save, and restart sendmail. Now you're "masquerading" as another, valid, server.


System Tips

DMA Errors
If you get the following (sporatic) messages on your system:
hda: dma_intr: status=0x51 { DriveReady SeekComplete Error }
hda: dma_intr: error=0x84 { DriveStatusError BadCRC }
...then try enabling the Multi-Mode DMA option located in the Block Devices section of your kernel config.



Mounting an ISO image:
(Must have /dev/loop support)
mount -t iso9660 -o ro,loop=/dev/loop0 {image}.iso /mnt/cdrom



To add NFS mounts to FTP service:
in /etc/exports:
/path/to/share system.domain.name(ro,no_root_squash,async)

in /etc/fstab:
computer:/path/to/share nfs ro 0 0
or: rw(no_root_squash)

Change shared dir's to group ftp
exportfs
mount -as



Turn off screen blanking:
setterm -blank 0



Turn off standby on harddrive:
/sbin/hdparm -S 0 /dev/hda (hdb, etc.)
/sbin/hdparm -k 1 /dev/hda (hdb, etc.)
(-k 1 saves through reboot)



Quick Crontab Howto:
minute (0-59) The exact minute that the command sequence executes
hour (0-23) The hour of the day that the command sequence executes
day (1-31 The day of the month that the command sequence executes
month (1-12) The month of the year that the command sequence executes
weekday (0-6) Sunday = 0, Monday = 1, Tuesday = 2, and so forth
command The complete sequence of commands to execute.

Note: The command string must conform to Bourne shell syntax. Commands, executables (such as scripts), or combinations are acceptable.



Check RAID Status (Email root If Bad):
0 * * * * root perl -ne '/ [(d)/(d)] / && $2 ne $1 && print "$a$_"; $a=$_;' /proc/mdstat