April 27, 2010 at 7:06 am · Filed under Programming
Here is a great little tut on getting started in Bash. I’d recommend it to anyone trying to hack their way into a shell script.
Here is a quick script for sending an email:
#!/bin/bash
# Subject of email
SUBJECT="Test email with attachment from a bash script"
# Where to send it
TO_ADDRESS="your@email.com"
# Where the attachment is
ATTACHMENT_FILE="/tmp/attachment.txt"
# For fun, let's put something into the attachment
echo "This goes into the file." > $ATTACHMENT_FILE
echo "This appends to the file." >> $ATTACHMENT_FILE
# send the message
/bin/mail -s "$SUBJECT" "$TO_ADDRESS" < $ATTACHMENT_FILE |
August 6, 2008 at 3:02 am · Filed under Programming
I wanted to drop all mysql tables from a db that had a certain prefix, such as xx_.
Well this turned out to be an adventure…
The First Attempt
The first solution I found was to use sed/grep sort of logic:
#mysqlshow -u username -p dbname xx\\_% |sed 's/[|+-]//g'|sed 's/[ ]*$/,/'>droptables.sql |
(xx\\_% is how you tell it to show tables starting with xx_)
This produced a semi-useful list. But I had to manually edit out the extra commas and line feeds to get a pure list, then add “DROP TABLE ” to the beginning of the list. Then feed this into mysql as follows:
#mysql -u username -p dbname < droptables.sql |
I wasn’t real happy with that answer, naturally, so I researched more…
A Better Solution
I came across an alternative in this command:
mysqldump -u username -p --add-drop-table --no-data dbname | grep "^DROP.*\`xx_" | mysql -u username -p dbname |
(replace xx_ with the prefix you want to remove, to do all tables, try just “grep ^DROP”
You can test it first by cutting off the last “| mysql…” bit and see the output, which is useful for debugging, before you go blowing away your tables.
August 3, 2008 at 1:24 pm · Filed under Programming
Had a service in CentOS 4 server that went down every time the box rebooted. Got tired of starting it manually so I had to go find the command to start it automagically.
Surprisingly, it has nothing to do with “service”, which is how you start/stop it manually. It has the very unintuitive command “chkconfig” to make it start on boot. What a choice: chckconfig!
Oh well, here it is:
chkconfig --add httpd
chkconfig httpd on |
November 26, 2007 at 3:30 am · Filed under Programming
find / -type f \( -perm -2 -o -perm -20 \) -exec ls -lg {} \; |
November 22, 2007 at 2:08 am · Filed under Programming
Tried to burn an ISO image in Feisty… although the CD-ROM drive is detected and it recognizes when I put a CD in, it won’t run. It shows a message like the following:
Please insert a rewritable or blank CD.
I hit the forums and found this very relevant discussion.[/url] Apparently the forums hit the forums… because their solution pointed to [url=http://www.xcdroast.org]www.xcdroast.org, who had this to say:
Linux Kernel 2.6.8 broke CD-Writing:
I had several reports that the last 2.6.x kernel broke CD-Writing using the ATAPI driver. Don’t update if you want to continue to use X-CD-Roast, or switch back to SCSI-emulation.
Update: When started from a root shell burning still works, but non-root mode is disabled by this kernel.
So the solution is to run the programs as root. I was able to burn my cd using:
root@Tiki:~# cdrecord dev=/dev/cdrw1 driveropts=burnfree -v -data /home/kato/Desktop/tmp/ubuntu-6.06.1-server-i386.iso |
Looks like others used sudo k3d with comparable success.
I didn’t bother trying to figure out which program the “Write to Disk” command traces back to. But it looks like K3d already has a fix. Maybe Ubuntu will provide a fix soon, too…
May 4, 2007 at 6:55 pm · Filed under Programming
/usr/bin/ssh -v -a -L 2401:localhost:2401 cvsnobody@ns2.cyterm.com |