开发者

Append variable to shell script like URL variables?

I'm using Carbon Copy Cloner to backup some files and run a shell script after the backup process has completed.

Note: You can save a scheduled backup in Carbon Copy Cloner and set it to run a specific shell script after the backup.

The shell script emailbackupstatus.sh looks like this 开发者_StackOverflowand works fine:

#!/bin/sh

(sleep 10; /usr/libexec/PlistBuddy -c "Print" /Library/Logs/CCC.stats | tail -n 9 | mail -s "Backup completed" myname@mydomain.com) &

Note: The plist file CCC.stats unfortunately does not contain the name of my saved backup schedule.

But as I have several scheduled backups running every day, I get several identical emails every day. Therefore I would like to append a variable to the shell script, so that I can change the email subject to something like this: "Backup of $backupName completed"

Pass variable to shell script:

Is it possible to somehow pass a variable to my shell script, like you can do with the GET url variables in PHP? Something like this: emailbackupstatus.sh&$backupName="Just testing"

Or even better:

Just get the name of my saved sheduled backup in Carbon Copy Cloner and append it to the email subject?

The email I get looks like this:

Dict {

targetDisk = root@backup.myserver.net:/Volumes/BACKUPDESTINATION/

date = Sun Dec 28 00:24:52 CET 2010

dataCopied = 0

elapsedTime = 1467.495361

sourceDisk = /Volumes/BACKUPSOURCE

exitStatus = 0

}

}


You can pass arguments to your shell script as you would to any other program:

$ some_script.sh arg1 arg2 arg3

Here is a small tutorial as to how to use them in your script.


$ ./script.sh foo bar mysubject

can be accessed by example as positional (numbered) variables:

#!/bin/bash

echo "Hello arg1=$1 and arg2=$2"

echo "here I am" |mail -s "My submject is $3" me@domain.com
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜