Archive for the 'Shell Script' Category

Using smb and rsync to backup

Monday, January 28th, 2008

I needed a script to backup a workfolder to a Windows network server. I wrote this perl script that can be triggered using cron. First create a mount point. I used /smb/public. So to do so in two steps, mkdir /smb, then mkdir /smb/public. I put my scripts in ~/bin. Put this perl script below […]

regex for path names

Saturday, February 24th, 2007

May seem simple to most folks, but just in case you are looking for an expression to remove the path before a file name here is an expression to start.
[\w/]*/
It searches for all the word characters before the last slash. If you need periods in the path add those to the character class.

Doing the Perl curl

Thursday, July 27th, 2006

A while back I wrote a post about a ftp shell script. A number of people told me I should use curl instead. Here is one I wrote using both perl and curl to move some files from a site. I start with a list of file names. They don’t have the .pdf extension in […]

Javascript from the command line

Thursday, April 13th, 2006

Javascript has come a long ways. The Mozilla project has released a couple of tools for javascript writers. I recently added the capability to my Mac of being able to write javascript then run and debug it from the command line, just like I would a perl script. Rhino is a java tool that will […]

Trusty Applications

Saturday, March 11th, 2006

I have several handy applications that I use on my mac daily. Obviously a mail app and browser. Safari is very nice. I’m using Apple Mail, but Thunderbird is really a nice mail app, too. But for me, much of the business of computing is storing information, and being able to get to that information […]

plists and launchd

Sunday, February 26th, 2006

Recently I wrote about getting Tomcat running in Mac OS X. You can easily start it up manually anytime you want by running the startup script in /Library/Tomcat/bin after you have it installed. But if you want it or any other daemon to run at startup you can use launchd if you are running Tiger. […]

grep through files

Thursday, January 26th, 2006

I have occasion to look for various text inside of files in a directory. Grep is great for that. To look for some text in a whole directory of files you can type on the command line grep matchtext *.txt. That will pull up the files with the matched text and print it out on […]

Applescript and shell move files script

Tuesday, January 24th, 2006

Do you ever need to move a bunch of files to a specific location? Or do you want to backup certain files and need a nice method for moving them to a second drive or location? This following script can be helpful. You can re-write it for your particular purpose. I originally wrote it to […]

Restart Mac Classic from a script

Monday, January 23rd, 2006

I’ve been asked this a couple of times, so I’m revisiting this topic (see post 50). I didn’t think it would have been too common for people to want to restart classic from a script, but apparently there are some. If this doesn’t interest you, at least you might want to take a peek at […]

email from the shell

Thursday, July 14th, 2005

Previously I showed a php script to send email. You can use php as a shell language as well as a web development language. PHP has ready made functions for this, so it is kind of an easy thing to do. Here is an example of a straight email shell script using bash.
#!/bin/bash
sendmail=”/usr/sbin/postfix”
recipient=”user@domain.com, user2@domain2.com”
( cat […]

Standard Input piped to a text editor

Wednesday, March 16th, 2005

If you have BBEdit and you have installed the command line tool you have a real nice resource for printing lists of file directories. Even without the command line you can drag a directory into a BBEdit window and create a file list of that directory. With the command line tool you can pipe standard […]

ftp by shell script

Monday, February 21st, 2005

I like to have a local copy of my website. With Wordpress, I write directly into my hosted site. So I have to occassionally ftp my host site to my local drive to keep them in sync. I have asked my site host to backup my sql database weekly. Then I can download it to […]

vi and shell editing

Thursday, February 10th, 2005

I use vi for editing my httpd.conf and other config files as well as for some c programming and shell programming. One of the things I never really used well was the interaction with the shell inside of vi. If you are like me and quit vi to do some shell commands and then reopen […]

pushd

Monday, January 17th, 2005

In the terminal, if you find yourself needing to move back and forth between two directories and don’t want to type in the complete path name constantly, you can either set up aliases of the cd command to the directory or you can use pushd. Let’s say you are in your Sites folder in […]

Crontab

Monday, January 10th, 2005

I have been having a lot of difficulty using Moveable Type in recent weeks. This has slowed progress on the website. I’ve made the switch to Wordpress which is a php alternative to the perl powered Moveable Type. I have found it to be a very nice editor that is very easy to install and […]

Restart Classic

Wednesday, November 17th, 2004

Here is a shell script you can use to shutdown and restart classic. I created this to run as a cron script, so that I could shut down classic at an interval. It seemed like Classic was having memory problems if it ran too long without a reboot, so I set it up to run […]

terminal mount command

Thursday, October 7th, 2004

I’ve been trying to understand the mount command in Unix. If anyone can shed some light on it, please do post. This is what I have figured out. You can mount an afp volume using the command mount -t afp. But you first have to establish a share point for the mount to land. So […]

printing a directory list

Thursday, August 26th, 2004

One thing that OS X is lacking that I used all of the time in OS 9 is the print window command in the finder. There are a few ways to get around this limitation. One way is to open the window you want a print out of. Grab the icon at the top middle […]

softwareupdate

Monday, August 16th, 2004

Apple has provided a command line utility to match the Aqua software update. This can be scripted to run and also can be run remotely using ssh.
I ran the softwareupdate command by typing in softwareupdate -i -r for install required. The discovery of this command line command is really rather nifty. Next time you need […]

Killing a process

Tuesday, July 20th, 2004

Sometimes applications crash, or at least they don’t behave the way they should. The kill command will come in handy when you need to kill an application. I use this command to find the Distiller pid then kill it:
kill -9 $(ps -auxwww | grep Distiller | grep -v grep | awk ‘{print $2}’)
One of the […]