Sh script - simple function won't work

I'm pretty much a newbie at scripts. I redid the backup script for my OS drive. And I wanted to try using a function for the final "dumping", because it's used a number of times for different scenarios. Well, it won't work and I don't know why. I'm sure it's something stupid. :\

This is the piece giving me trouble:
Code:
# Dump
DIR="/backup/weekly.dump"
DATE=$(date +"%m-%d-%Y")

dump() {
	
        echo "---> Dumping UFS (/) filesystem..."; echo
	dump -0Lauf - /dev/ad4s1a | gzip > $DIR/root_$DATE.dump.gz
}

And I call it with a simple "dump" near the end. But get this:

Code:
---> Dumping UFS (/) filesystem...

./freebsd-backup: Cannot fork: Resource temporarily unavailable
./freebsd-backup: Cannot fork: Resource temporarily unavailable

What does it mean? It isn't the commands, I use them all the time. The file even shows up, formatted correctly on the network drive I mount on /backup. But it errors out after that.
 
I think it gets confused between the function dump and the executable dump. Try using the full path to the dump(8) command.
 
Snap. I realized that could be the problem, right after posting. Did I mention I was pretty new at this? :(

I changed the name of the function and it worked. Full path is good too, I want to keep its name as dump. Thank you.
 
dbsd said:
Snap. I realized that could be the problem, right after posting. Did I mention I was pretty new at this? :(

I changed the name of the function and it worked. Full path is good too, I want to keep it's name as dump. Thank you.

You could set the path to a variable like so:

Code:
DUMP=/sbin/dump
or
Code:
DUMP=`which dump`

then inside your function call it:

Code:
${DUMP} -0Lauf - /dev/ad4s1a | gzip > $DIR/root_$DATE.dump.gz
 
Back
Top