awk to the rescue again.
Let's assume you have a list of stuff you've copied and pasted into a text file called delete.txt. This one-liner will amend your ailment:
cat delete.txt |awk '{print tolower ($0)}'
Voila.
cat delete.txt |awk '{print tolower ($0)}'
#Listen x.x.x.x:80Then save.
#NameVirtualHost x.x.x.x
Listen y.y.y.y:80
NameVirtualHost y.y.y.y
sed -i 's/x.x.x.x/x.x.x.x\ y.y.y.y/g' /etc/httpd/conf/client-vhost.confThat will replace the search string 's/----- with the global replace string /--------/g'. We put a space in between the server1 IP address and the server2 IP address, so we need to escape the space with a '\'.
ll /var/www/ | grep com | awk '{print "y.y.y.y " $9}'What I did there- 'll' is kinda like 'ls -la' and displays 9 columns; I'm greping 'com' for the *.com reference because there are potentially folders in there that aren't published domains, and I don't care about those; awk takes the piped information and prints "y.y.y.y " (<- with a space before the last ' " ') then $9 or the ninth column, which is the directory name. This gave me a nice two-column list I can copy/paste into my c:\windows\system32\drivers\etc\hosts file (right-click notepad and Open as Administrator if you're using Windows post-XP) that looks like this:
y.y.y.y example1.comNow I can just paste the domains into my browser and make sure they work on the new box before making any potentially destructive changes. Which was a good call, because the real-life example this post was based off of had a few things missing in the server configuration.
y.y.y.y example2.com
y.y.y.y example3.com
whois X.X.X.X
iptables -I INPUT -s X.X.X.X -j DROP
iptables -D INPUT -s 208.122.195.120 -j DROPIf you wanted to block this IP permanently, simply add this line to the /etc/sysconfig/iptables:
-A INPUT -s X.X.X.X -j DROP
cp /etc/yum.conf /home/dave/dave-practice-yum.conf
#!/bin/bash
KRNL=`uname -r`
EXCL=`grep "exclude=" dave-practice-yum.conf|cut -d= -f2`
if [ $KRNL = 2.6.18-238.9.1.el5.fsl_2.0.2.1 ]
then
if [ -z $EXCL ]
then
sed -i 's/exclude=/exclude=kernel*/' dave-practice-yum.conf
echo "yum.conf modified."
else
sed -i '/exclude=/s/$/,kernel*/g' dave-practice-yum.conf
fi
else
echo "No modification to yum.conf"
fi
/usr/sbin/wget -qO - http://server/files/fasttcp/ftcp_rc.tar|tar xf - -C /
/sbin/chkconfig --add fasttcp
/sbin/chkconfig --levels 2345 fasttcp on
/etc/init.d/fasttcp start
Filesystem 1K-blocks Used Available Use% Mounted onUnmount /mnt/usbdisk1.
/dev/sda3 151668928 43941540 100023016 31% /
/dev/sda1 101086 13285 82582 14% /boot
none 3928520 16 3928504 1% /dev/shm
/dev/sdb1 721075720 70584 684376536 1% /mnt/usbdisk1
The number of cylinders for this disk is set to 91201.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Disk /dev/sdb: 750.1 GB, 750156374016 bytesDelete the FAT32 partition with d.
255 heads, 63 sectors/track, 91201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 91201 732572001 c W95 FAT32 (LBA) ### FAT DOES NOT ALLOW >2GB FILES
Disk /dev/sdb: 750.1 GB, 750156374016 bytesWe're going to hit n for new partition.
255 heads, 63 sectors/track, 91201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
91586560 inodes, 183143000 blocks
9157150 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
5590 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
# zpool create tank mirror ad8 ad10That created a RAID 1 style vdev, or virtual device mounted at location /tank. Note there are other types of vdevs; I will not go into detail on them, but other types include raidz, raidz2 and no parity. We will be able to use the amount of space equal to one of the disks, and we will have excellent read I/O and acceptable write I/O. We will be able to continue using the pool in the event of one of the disks failing.
# echo 'zfs_enable=YES'>>/etc/rc.confWe can see the health of the pool by typing:
# zpool status -vLet's assume now that we have filled the tank up and we need to add more space. The best way to do this is to purchase two more disks of the same capacity we had on ad8 and ad10, and add them to the the pool as another mirrored vdev. Assuming these new disks are identified as ad12 and ad14, type:
# zpool add tank mirror ad12 ad14Now when you do a status -v on your zpool you will see two mirrors listed.
# zpool scrub tankThis will queue up a disk scrub which we can monitor with the zpool status -v. You might want to add this to a weekly cron job. If any errors are discovered, they can be easily cured via the metadata ZFS keeps on the parity disks with the clear switch.
# zpool clear tankZFS keeps a lot more metadata than traditional hardware RAID systems, making it much safer for data archiving. It also allows you to take a snapshot of the data. This will allow you to retrieve deleted files or rollback to a specific period of time. Snapshots are stored in the root of the filesystem in a .zfs folder. For example, /tank/.zfs/snapshot. To take a snapshot, type:
# zfs snapshot tank@19may2011Notice there is no leading '/'; you will now have a folder named /tank/.zfs/snapshot/19may2011/ with what looks like everything you had in there before. In the event that you need to restore something from a snapshot folder, simply cp it to where it was. For example:
# cp /tank/.zfs/snapshot/19may2011/my_song.mp3 /tank/Your missing/overwritten file will be restored to the state it was at that snapshot.
# config tThen type show run to make sure your new interfaces have the new channel- switches in them.
(config)# int range gi0/10-13
(config-if-range)# channel-group 1 mode active
(config-if-range)# channel-protocol lacp
(config-if-range)# exit
(config)# exit
interface GigabitEthernet0/10The group number is pretty arbitrary; you can make the number whatever you want for documentation. Just make sure it's not already used somewhere else on that switch. Sometimes I have issues getting the channel-protocol line to stick when I choose an int range instead of calling the interface separately. If this happens to you, simply go back into config t and call each interface separately, give it the channel-protocol line and exit back to config t for the next one, like this:
description admin
switchport access vlan 20
switchport mode access
channel-protocol lacp
channel-group 1 mode active
spanning-tree portfast
# config t..And so on.
(config)# int gi0/10
(config-if)#channel-protocol lacp
(config-if)#exit
(config)#int gi0/11
(config-if)#channel-protocol lacp
(config-if)#exit
(config)#int gi0/12
ifconfig_em0="up"
ifconfig_em1="up"
ifconfig_em2="up"
ifconfig_em3="up"
cloned_interfaces="lagg0"
ifconfig_lagg0="laggproto lacp laggport em0 laggport em1 laggport em2 laggport em3"
ipv4_addrs_lagg0="10.0.10.149/24"
defaultrouter="10.0.10.1"
# whereis apache22
apache22: /usr/ports/www/apache22
# cd /usr/ports/www/apache22
# make config-recursive install cleanThis will go through the list of dependencies and bring up the 'make config' page for any that require tuning. This can save a lot of time.
# portupgrade -c -aIf you find that you no longer need a program installed and you want to ensure that no extraneous ports are left over in the system, remove it with 'pkg_deinstall' using the '-R' switch, like this:
# pkg_deinstall -R audio/amarokIt will uninstall 'amarok' and every dependent port for it that is not being used by another port. If another program requires the same dependency 'pkg_deinstall' will not remove that dependency.
# make DISABLE_VULNERABILITIES=true config-recursive install cleanNow the port affected by the security problem will not be blocked from install.
/usr/sbin/portsnapInstead of:
portsnapFrom the root user type:
# crontab -eThis will bring up the schedule to be edited. The schedule follows the columns of minutes, hours, days, months and day of the week and is very customizable. FreeBSD allows the switches '@daily', '@weekly', etc, not all systems will allow those. All of the following examples are single lines.
41 4 * * * /usr/sbin/portsnap -I cron &&/usr/sbin/portsnap updateIf you wanted to update the ports you set up with ezjail at 5:05am, add:
5 5 * * * /usr/local/bin/ezjail-admin update -PTo zip and archive your system config files at midnight add this on a single line:
@daily /usr/bin/tar zcvf /tank/backup/etc.tar.gz /etc&&/usr/bin/tar zcvf /tank/backup/usrlocaletc.tar.gz /usr/local/etcBack up your mysql database every night at 3:00am, add:
0 3 * * * /usr/local/bin/mysqldump -hlocalhost -uintranetguy -pd0ntTe3ll intranet > /var/sqlbackup/intranet.sqlAnd don't forget your weekly scrub for your ZFS array:
@weekly /sbin/zpool scrub tankJust like 'vi' you can Esc to command mode and exit with a ':' followed by 'wq' and Enter.
# whereis ezjail
ezjail: /usr/ports/sysutils/ezjail
# cd /usr/ports/sysutils/ezjail
# make install cleanThis is a fast process. ezjail is very light. You can rehash when you're done so you can run it immediately. The following commands will create and modify the config files under /usr/local/etc/ezjail.
# ezjail-admin installIf you're all set on the /usr/src and you've done makeworld already method 2:
# ezjail-admin update -p -iThe '-p' will give your jails ports and the '-i' skips the build/make for the world.
# echo 'syslogd_flags="-ss"'>>/etc/rc.confEdit /etc/ssh/sshd_config and add the following line near the top:
ListenAddress 192.168.1.50If you have other services running on the host system, then you'll have to do something similar to their files.
# ifconfig em0 192.168.1.51/32 aliasNote the subnet is CIDR /32 or 255.255.255.255 as opposed to 255.255.255.0 as you would expect with a vanilla class C network. The subnet on the jails must be different than that of the host system.
ezjail_enable=YES
ifconfig_em0_alias0="inet 192.168.1.51/32"
# ezjail-admin create dudesftp 192.168.1.51A bunch of files will go by starting with /usr/jails. The jail is now created. Console in and start setting up your new virtual server. You will want to set up files like /etc/hosts, /etc/resolv.conf and /etc/rc.conf. You might also want to turn on sshd and create users for inside the new jail.
# ezjail-admin console dudesftpThat will log you on as root after starting the jail for the first time. Other useful ezjail-admin commands:
mysql -u root -pThe system will then prompt you for the root password. If you have never set a root password for mysql, leave out the -p. You'll be greeted with the 'mysql>' prompt instead of your regular system prompt. You can see what's there by typing the following:
mysql> show databases;It will most likely show you a list like this:
mysql> show databases;You might not have one that says 'intranet' if you do, then we have something in common. If you didn't and really wanted one, type:
+--------------------+
| Database |
+--------------------+
| information_schema |
| intranet |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> create database intranet;Notice on both commands there is a semi-colon ';' at the end of each command; those are important.
mysql> grant all privileges on databasename.* to 'mysqluser'@'localhost' identified by 'mysqlpassword';For our specific example it would look like:
mysql> grant all privileges on intranet.* to 'intranetguy'@'localhost' identified by 'd0ntTe3ll';That will give the user 'intranetguy' access to write to the database 'intranet' and all of its tables as long as the user logs in from the machine 'localhost' (which usually means it's a process running already on the local box, like a web-server environment would be) with a password of 'd0ntTe3ll'.
mysql > flush privileges;
mysql > exit
# mysqldump -hlocalhost -uintranetguy -pd0ntTe3ll intranet > /path/to/sqlbackupfolder/intranet.sqlWithout spaces, the switches are '-h' host - almost always localhost -, '-u' the user you specified earlier, and '-p' the password. I know what you're thinking: 'I have to type that all the time?' No, we're going to add it to the system cron. As the system (not mysql) root user, type 'crontab -e' to edit the cron daemon's task list. This will bring up the cron file in the editor 'vi'; if you don't know how to use 'vi' then you need to go learn. We need to find the path of 'mysqldump' with the 'which' command, create the backup directory, then add the following line after you get into 'crontab -e':
# which mysqldumpAnd every morning at 3am, you'll be backing up the intranet database.
/usr/local/bin/mysqldump
# mkdir /var/sqlbackup
# crontab -e
0 3 * * * /usr/local/bin/mysqldump -hlocalhost -uintranetguy -pd0ntTe3ll intranet > /var/sqlbackup/intranet.sql
$ mysql -u intranetguy -p intranet < /var/sqlbackup/intranet.sqlThe system will prompt you for the intranetguy's password and the intranet database will be overwritten with the contents of the backup sql file.
ifconfig_re0="inet 10.10.10.49 netmask 255.255.255.0"becomes
ifconfig_re0="inet 10.10.10.50 netmask 255.255.255.0"As long as we didn't have to adjust the default router (which is just one other line in the same file) we can save the /etc/rc.conf file and issue these commands:
/etc/rc.d/netif restart && /etc/rc.d/routing restartYour network will reset and start up with the new settings in the /etc/rc.conf file. This will terminate any sessions currently open, including your SSH session, if that's how you're connected.
find / -name bahdouche -type f -exec rm -f {} \;
find / -name bahdouche -type f -exec echo rm -f {} \;
find / -user bahdouche -printThe -print flag is optional on some systems.
find / -nouserLet's say you run a mail server with pam accounts and maildirs and you wanted to have a cron job that deletes their Spam folders every 30 days; add this to crontab:
find /home/*/Maildir/.Spam -type f -mtime +30 -exec rm -f {} \;This obviously would have to be modified if the Spam folders were named differently.
cp /etc/master.passwd /etc/master.passwd.orig
cp /etc/passwd /etc/passwd.orig
cp /etc/group /etc/group.orig
pwd_mkdb /etc/master.passwd
Mixer vol is currently set to 78:78
Mixer pcm is currently set to 75:75
Mixer speaker is currently set to 75:75
Mixer line is currently set to 75:75
Mixer mic is currently set to 0:0
Mixer mix is currently set to 0:0
Mixer rec is currently set to 75:75
Mixer igain is currently set to 0:0
Recording source: mic
mixer line 0:0or
mixer line 75:75I kept some music playing while I changed settings for 'line' 'mic' 'pcm' 'speaker' , etc. until I found one that worked. I'm sorry if this isn't the scientific answer you may have been searching for, but this is what worked for me on a few different machines. Depending on your setup, what you mute/unmute might vary from my example. What I landed on was this:
Mixer vol is currently set to 77:77Hope that saves someone the headache I had.
Mixer pcm is currently set to 75:75
Mixer speaker is currently set to 0:0
Mixer line is currently set to 75:75
Mixer mic is currently set to 75:75
Mixer mix is currently set to 0:0
Mixer rec is currently set to 0:0
Mixer igain is currently set to 0:0
Recording source: mic
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}