# Sh script - simple function won't work



## dndlnx (Jun 5, 2012)

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:

```
# 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:


```
---> 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.


----------



## SirDice (Jun 5, 2012)

I think it gets confused between the _function_ dump and the _executable_ dump. Try using the full path to the dump(8) command.


----------



## dndlnx (Jun 5, 2012)

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.


----------



## UNIXgod (Jun 5, 2012)

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:


```
DUMP=/sbin/dump
```
or

```
DUMP=`which dump`
```

then inside your function call it:


```
${DUMP} -0Lauf - /dev/ad4s1a | gzip > $DIR/root_$DATE.dump.gz
```


----------

