Shell scripting questions
I've been looking through some basic shell books, and some online resources, that I have but I'm not finding the answer. Or maybe I just don't recognize the answer when I see it... I'm building a schell script that will backup my systems to CD-ROM. Or DVD when I can talk my wife into a burner. :-) I'm stuck on two items: 1) Since my tar files CAN exceed the capacity of a CD-ROM, I want to check in the script if I have to call split. The closest I can come to determining the size of the output file from tar (e.g.ad0s1a.tgz) is: file_size=`du -k /tmp/ad0s1a.tgz`. The problem I have is, while this gives me the result in number of K blocks, it also returns the file name and directory. I don't know how to get JUST the number of K blocks so I can do a numeric compare against 700m. 2) I have a function written that will tar/gzip the filesystem then split it into pieces that will be turned into .iso files that will be fed to burncd. I would like to capture the output of commands (e.g. ls -l /tmp/ad0s1a.*) into a table that I can examine to determine what was output by the split command so I know what mkisofs commands, and how many, I have to build/execute. Example: If I end up with a ad0s1a.tgz.aa, ab, and ac from split, I know I have to do mkisofs' for 3 files. I also hope to use the same technique for determining what filesystems I have to backup in the first place. e.g. If I do a df command I want to pull out the filesystem name and what mountpoint it is on. The mountpoint is important to me because I do not want to back up some filesystems. e.g. I do not want to backup /tmp. TIA. Cheers... To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Shell scripting questions
On Mon, 17 Mar 2003, Tom Parquette wrote: The closest I can come to determining the size of the output file from tar (e.g.ad0s1a.tgz) is: file_size=`du -k /tmp/ad0s1a.tgz`. You can get just the first coloumn of something by doing something like du -k /tmp/ad0s1a.tgz | awk '{ print $1 }'. That should help you a bit for that 2) I have a function written that will tar/gzip the filesystem then split it into pieces that will be turned into .iso files that will be fed to burncd. I would like to capture the output of commands (e.g. ls -l /tmp/ad0s1a.*) into a table that I can examine to determine what was output by the split command so I know what mkisofs commands, and how Could you do something like for i in /tmp/ad0s1a.tgz.?? ; do mkiosfs . ; done I also hope to use the same technique for determining what filesystems I have to backup in the first place. e.g. If I do a df command I want to pull out the filesystem name and what mountpoint it is on. The You might have slightly nicer format if you use just the mount command on its own. If you couple it with the awk command say mount | awk '{ print $1,$2 }' Play have fun :) Rgds Rus -- http://www.65535.net | MSN: [EMAIL PROTECTED] | e: [EMAIL PROTECTED] More bits for your bite Lifetime FreeBSD + Linux Hosting and Shell Accounts Please respect RFC1855 and don't top post To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Shell scripting questions
On Mon, 17 Mar 2003 14:38:01 -0500 Tom Parquette [EMAIL PROTECTED] wrote: I've been looking through some basic shell books, and some online resources, that I have but I'm not finding the answer. Or maybe I just don't recognize the answer when I see it... I'm building a schell script that will backup my systems to CD-ROM. Or DVD when I can talk my wife into a burner. :-) I'm stuck on two items: 1) Since my tar files CAN exceed the capacity of a CD-ROM, I want to check in the script if I have to call split. The closest I can come to determining the size of the output file from tar (e.g.ad0s1a.tgz) is: file_size=`du -k /tmp/ad0s1a.tgz`. The problem I have is, while this gives me the result in number of K blocks, it also returns the file name and directory. I don't know how to get JUST the number of K blocks so I can do a numeric compare against 700m. file_size=`du -k /tmp/ad0s1a.tgz|awk '{print $1}'` num_compare=`expr 70 - $file_size` 2) I have a function written that will tar/gzip the filesystem then split it into pieces that will be turned into .iso files that will be fed to burncd. I would like to capture the output of commands (e.g. ls -l /tmp/ad0s1a.*) into a table that I can examine to determine what was output by the split command so I know what mkisofs commands, and how many, I have to build/execute. Example: If I end up with a ad0s1a.tgz.aa, ab, and ac from split, I know I have to do mkisofs' for 3 files. I don't know what your split command returns but I beleive u can put that in a loop. I also hope to use the same technique for determining what filesystems I have to backup in the first place. e.g. If I do a df command I want to pull out the filesystem name and what mountpoint it is on. The mountpoint is important to me because I do not want to back up some filesystems. e.g. I do not want to backup /tmp. I think that all u're missing here is the awk command. man awk ;) fs=`df|awk '{print $6}'|grep -vi mounted` for i in $fs do if [ $i = / ] then backup_script args elseif [ $i = /etc ] backup_script args else elseif [ $i = /tmp ] echo I'm not backing up /tmp ! else do something fi done TIA. Cheers... hope this helps. Ed. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message -- Edmond Baroud UNIX Systems Admin mailto:[EMAIL PROTECTED] Fingerprint 140F 5FD5 3FDD 45D9 226D 9602 8C3D EAFB 4E19 BEF9 UNIX is very user friendly, it's just picky about who its friends are. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Shell scripting questions
On Mon, 17 Mar 2003 15:09:47 -0500 Edmond Baroud [EMAIL PROTECTED] wrote: On Mon, 17 Mar 2003 14:38:01 -0500 Tom Parquette [EMAIL PROTECTED] wrote: I've been looking through some basic shell books, and some online resources, that I have but I'm not finding the answer. Or maybe I just don't recognize the answer when I see it... I'm building a schell script that will backup my systems to CD-ROM. Or DVD when I can talk my wife into a burner. :-) I'm stuck on two items: 1) Since my tar files CAN exceed the capacity of a CD-ROM, I want to check in the script if I have to call split. The closest I can come to determining the size of the output file from tar (e.g.ad0s1a.tgz) is: file_size=`du -k /tmp/ad0s1a.tgz`. The problem I have is, while this gives me the result in number of K blocks, it also returns the file name and directory. I don't know how to get JUST the number of K blocks so I can do a numeric compare against 700m. file_size=`du -k /tmp/ad0s1a.tgz|awk '{print $1}'` num_compare=`expr 70 - $file_size` 2) I have a function written that will tar/gzip the filesystem then split it into pieces that will be turned into .iso files that will be fed to burncd. I would like to capture the output of commands (e.g. ls -l /tmp/ad0s1a.*) into a table that I can examine to determine what was output by the split command so I know what mkisofs commands, and how many, I have to build/execute. Example: If I end up with a ad0s1a.tgz.aa, ab, and ac from split, I know I have to do mkisofs' for 3 files. I don't know what your split command returns but I beleive u can put that in a loop. I also hope to use the same technique for determining what filesystems I have to backup in the first place. e.g. If I do a df command I want to pull out the filesystem name and what mountpoint it is on. The mountpoint is important to me because I do not want to back up some filesystems. e.g. I do not want to backup /tmp. I think that all u're missing here is the awk command. man awk ;) fs=`df|awk '{print $6}'|grep -vi mounted` for i in $fs do if [ $i = / ] then backup_script args elseif [ $i = /etc ] backup_script args u dont need this else I forgot to remove it in this example :) else elseif [ $i = /tmp ] echo I'm not backing up /tmp ! else do something fi done TIA. Cheers... hope this helps. Ed. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message -- Edmond Baroud UNIX Systems Admin mailto:[EMAIL PROTECTED] Fingerprint 140F 5FD5 3FDD 45D9 226D 9602 8C3D EAFB 4E19 BEF9 UNIX is very user friendly, it's just picky about who its friends are. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message -- Edmond Baroud UNIX Systems Admin mailto:[EMAIL PROTECTED] Fingerprint 140F 5FD5 3FDD 45D9 226D 9602 8C3D EAFB 4E19 BEF9 UNIX is very user friendly, it's just picky about who its friends are. To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message
Re: Shell scripting questions
On 2003-03-17 14:38, Tom Parquette [EMAIL PROTECTED] wrote: I've been looking through some basic shell books, and some online resources, that I have but I'm not finding the answer. Or maybe I just don't recognize the answer when I see it... I'm building a schell script that will backup my systems to CD-ROM. Or DVD when I can talk my wife into a burner. :-) I'm stuck on two items: 1) Since my tar files CAN exceed the capacity of a CD-ROM, I want to check in the script if I have to call split. I would probably run the output of tar through split anyway, and let split take care of the rest. In one of the Linux machines I have to take care of, the backup script does the following: cd /mnt/backup tar -cf - / --exclude /mnt --exclude /proc --exclude /var/tmp \ --exclude /var/run --exclude /tmp --exclude /dev | \ gzip -9c - | \ split -b 1073741824 - `date '+backup-%Y%m%d.tgz-'` The final step that calls split will break the backup output in chunks of 1 GB, which I can then join on extraction with: cat backup-20030318.tgz-?? | tar ... The closest I can come to determining the size of the output file from tar (e.g.ad0s1a.tgz) is: file_size=`du -k /tmp/ad0s1a.tgz`. The problem I have is, while this gives me the result in number of K blocks, it also returns the file name and directory. I don't know how to get JUST the number of K blocks so I can do a numeric compare against 700m. Why du not plain ls? $ /bin/ls -l ~/lyrics/rainbow.lyr -rw-rw-r-- 1 giorgos giorgos 1420 Mar 18 07:00 lyrics/rainbow.lyr $ /bin/ls -l ~/lyrics/rainbow.lyr | awk '{print $5}' 1420 $ 2) I have a function written that will tar/gzip the filesystem then split it into pieces that will be turned into .iso files that will be fed to burncd. I would like to capture the output of commands (e.g. ls -l /tmp/ad0s1a.*) into a table that I can examine to determine what was output by the split command so I know what mkisofs commands, and how many, I have to build/execute. Example: If I end up with a ad0s1a.tgz.aa, ab, and ac from split, I know I have to do mkisofs' for 3 files. I'm not sure I understand what the question is here. I also hope to use the same technique for determining what filesystems I have to backup in the first place. e.g. If I do a df command I want to pull out the filesystem name and what mountpoint it is on. The mountpoint is important to me because I do not want to back up some filesystems. e.g. I do not want to backup /tmp. You can always use something like this: $ df | grep '^/dev/ad' | awk '{print $1,$6}' /dev/ad0s1a / /dev/ad0s3e /var /dev/ad0s3g /usr /dev/ad0s3f /home - Giorgos To Unsubscribe: send mail to [EMAIL PROTECTED] with unsubscribe freebsd-questions in the body of the message