Results 1 to 9 of 9
Hi All,
What's the easiest way for me to make a program that requests a file location and then tar balls it.
I basically want to start making a simple ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-30-2010 #1
Bash file which requests file name
Hi All,
What's the easiest way for me to make a program that requests a file location and then tar balls it.
I basically want to start making a simple method of using pv with tar (lzma). I have a bit of coding backround but not a ton so any help would be greatly appreciated. Thanks all!Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 11-30-2010 #2
I have this:
#!/bin/bash
echo -e "Please enter the full directory that you want to compress: \c "
read uncompressed
echo "The word you entered is: $uncompressed"
echo -e "Please enter the final name with directory? "
read compressed
echo "Here is your input: \"$compressed\""
tar --lzma -cf - $uncompressed | pv -s $(du -sb $uncompressed | awk '{print $1}') | gzip > $compressed
Look pretty good??Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 12-02-2010 #3Just Joined!
- Join Date
- Nov 2010
- Location
- Canada
- Posts
- 9
I've tried a few different methods and haven't been able to find a good solution to your problem. I do have the following suggestions though.
If you want lzma compression, then you'll have to do something similar to option 1 (a or b) below. Or if you can handle the compression being gzip (for example), you could use option 2 with a progress bar. (see below)
Option 1a: lzma compression, no progress bar
Option 1b: lzma compression, no progress barCode:tar --lzma -pcf $destination $source
Option 2: gzip compression with progress barCode:tar pcf $source | lzma -c -z > $destination
The problem I see with your code is that your asking tar to use lzma compression but then you're piping it to gzip for output. This will give you an unreadable file (at least on my system it did).Code:tar pcf - $source | pv -s $(du -sb $source | awk '{print $1}') | gzip > $destination
Someone else has created/developed a script that creates a text progress bar from different kinds of sources. You could see if that works and/or if you like it better. The output is very clean but I think it's a lot of overhead processing for just a text progress bar. Unfortunately, the site won't let me link to another website but if you do a google search using the following terms: "bat cat with ASCII progress bar" without the quotes, it should be the 2nd link with a name like "Theiling Online: ASCII bar". I hope that wasn't a violation of forum rules.
I tend to like to use zenity for most of my scripts so that would be what I suggest. If you don't know what it is, it's basically a user interface that allows a script to interact with a user (no terminal needed). It has a built in file selection dialog so there's minimal to do there. The most complicated part would be piping the output of the compression process to its progress bar. I'm sure there's a lot of information on how to do that. If you need help, I could take another look. Of course, all of this assumes you have a system that has zenity.
Anways, I hope this helps or at least someone else can give you the answers you're looking for. Good luck.
- 12-02-2010 #4
Thanks for the reply, I've made some progress using this:
The code works fine but it's not showing a progress bar. I need to figure out how to run 7z through pv so that I get the nice looking bar that I want. Any ideas? The script does work as is and shows a percent, just no bar#!/bin/bash
echo -e "Please enter the full directory that you want to compress: \c "
read uncompressed
echo "The directory you entered is: $uncompressed"
echo -e "Where would you like the compressed file to be stored? "
read dir
echo "Here is your input: \"$dir\""
echo -e "What would you like the file name to be? "
read compressed
echo "Here is your input: \"$compressed\""
echo -e "How Compressed Would You Like The File to Be?"
read scale
echo "Here is your input: \"$scale\""
7z a -t7z $dir\/$compressed $uncompressed -mx$scaleBodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 12-03-2010 #5Just Joined!
- Join Date
- Nov 2010
- Location
- Canada
- Posts
- 9
I seldomly compress files/directories via the terminal so I had to do a little digging and some trial and error but I have 2 versions below of what should work (1st without progress bar, 2nd with progress bar).
Note: There are some limitations of using 7z directly under *nix (from the manual): It doesn't store owner/group of files/directories, 7z cannot directly compress directories (tar must be used)
Option 1: No Progress Bar
Option 2: With Progress BarCode:tar pcf - $source | 7z a -si $destination -mx$scale
You could also do some error checking to ensure the user has input the correct settings. For example, try using 'case' to ensure the correct compression is given. You could then have an option where the user is asked again if there wasn't a correct response.Code:tar pcf - $source | pv -s $(du -sb $source | awk '{print $1}') | 7z a -si -bd $destination -mx$scale
Again, most of my scripts include zenity so that I can just launch it from my desktop with minimal typing but still have a visual indicator of what's going on. But it sounds like you need/want to stick with the terminal (nothing wrong with that, I think most do).
I hope the above helped. Good luck.
- 12-04-2010 #6
Works great, thank you much. Can I ask where you found out how to use pv in this way? I looked forever and couldn't find it. Thanks again!
Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 12-04-2010 #7Just Joined!
- Join Date
- Nov 2010
- Location
- Canada
- Posts
- 9
I just took your original code and made the changes that needed to be made. I had to do some looking and reading of the manual for each command but it wasn't too bad. You may have had trouble based on what search terms you were using. Either one missing to narrow the search or one that might have thrown you search results off.
I'm glad to hear that you've got it working. Cheers.
- 02-22-2011 #8
I just found out the script doesn't work for files/folders that have spaces....any ideas??
Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 02-23-2011 #9Just Joined!
- Join Date
- Nov 2010
- Location
- Canada
- Posts
- 9
I don't have time to double check but you should be able to just add quotes around the source and destination strings to allow for the spaces. (see below)
Code:tar pcf - "$source" | 7z a -si "$destination" -mx$scale


Reply With Quote

