[SOLVED] Command Line Substutions and Variables using Korn for First Backup Script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You seemed to have made a lot of progress, but I am curious why in such a small script you would place commands into variable names to then only be called??
Code:
search=find
There appears to be no value in this line as when you then call the function:
How did that help seeing you could have just used the word find here??
So your last question does not seem to make much sense. Your saying the exact same line executed in a script does not perform the same as the command line??
At this point all is working well. As you can see from my "tail -f /home/davider/Downloads/full_status061811.log" it is running as designed.
Now, when I add that to my script:
Code:
results=$1
backup_dir=/home/davider/Downloads
date=$(date +%m%d%y)
search=find
archive="cpio -oav"
if [[ -d $backup_dir && $results = "full" ]] ; then
cd /home
$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
fi
if [[ -d $backup_dir && $results = "incremental" ]] ; then
cd /home
$search . -depth -mtime -1 -print | $archive > $backup_dir/inc$date.cpio 2> $backup_dir/inc$date.log
fi
case "$results"
in
full) echo full;;
incremental) echo incremental;;
*)echo "Incorrect syntax usage. Use <saint.ksh> {full|incremental} or target directory does not exist. Please verify share exist";;
esac
and then I run the script with a debug, it works except it is not using "\( -wholename \./\.\* \) -prune" to exclude my hidden directories under "~/home":
May I also point out that I am not entirely sure the process is working as you expect even when you say it is working.
What i mean is, your explanation / proof that it is working correctly is the tail of your log file. Yet the issue I have with that is the log file only contains
errors, ie you are doing 2> which means redirect standard error to the log file. So the output of the file you have shown:
May I also point out that I am not entirely sure the process is working as you expect even when you say it is working.
What i mean is, your explanation / proof that it is working correctly is the tail of your log file. Yet the issue I have with that is the log file only contains
errors, ie you are doing 2> which means redirect standard error to the log file.
the native shell that I am using is bash. Strangely enough this does work even with 2> /home/davider/Downloads/full$date. I dont understand why it is send this information as errors but here is my proof and trust me it works.
May I also point out that I am not entirely sure the process is working as you expect even when you say it is working.
What i mean is, your explanation / proof that it is working correctly is the tail of your log file. Yet the issue I have with that is the log file only contains
errors, ie you are doing 2> which means redirect standard error to the log file. So the output of the file you have shown:
Code:
~$ tail -f /home/davider/Downloads/full_status061811.log
./Pictures/10_25_2006/ScanImage69.jpg
./Pictures/10_25_2006/ScanImage97.jpg
./Pictures/10_25_2006/ScanImage01.jpg
the native shell that I am using is bash. Strangely enough this does work even with 2> /home/davider/Downloads/full$date. I dont understand why it is send this information as errors but here is my proof and trust me it works.
I did what you ask and its the same thing. I know it has to be something like [[]],"",'' or something like it. help? I know it is something small and stupid.
Last edited by metallica1973; 06-18-2011 at 11:15 PM.
Ok so you have shown that it seems to be working, would you please try my other test of doing set -x on the command line and then running the steps there.
This will show you if there is any difference with how the shell may be interpreting things. Of course you could also change your shell to ksh and perform
the tasks at the command line to see what results you get.
I think you missed my point here. By issuing the set -x on the command line you can now see that the line you were
worried about is interpreted exactly the same at the command line as it is in the script. You said that when
issued from the command line that you are receiving the correct results (I assume this is still the case?).
The above only goes to show that it is not the fact that the items in question have single quotes around them that is
making the difference as you have now proven it happens both in the script and on the command line.
I was able to resolve the isue. By using wholename and the way I was using it caused issues with interpretation of:
Code:
\( -wholename \./\.\* \) -prune
I instead switched to using -path which:
PHP Code:
-path pattern File name matches shell pattern pattern. The metacharacters do not treat `/' or `.' specially; so, for example, find . -path "./sr*sc" will print an entry for a directory called `./src/misc' (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory `src/emacs' and all files and directories under it, and print the names of the other files found, do something like this: find . -path ./src/emacs -prune -o -print Note that the pattern match test applies to the whole file name, starting from one of the start points named on the command line. It would only make sense to use an absolute path name here if the relevant start point is also an absolute path. This means that this command will never match anything:
and with winning results I was able to get the script doing what I want to do.
Code:
~$ ksh -x Documents/scripts/saint.ksh full
+ results=full
+ backup_dir=/media/caca/extract
+ date +%m%d%y
+ date=062011
+ search=find
+ archive='cpio -oavc'
+ [[ -d /media/caca/extract ]]
+ [[ full == full ]]
+ cpio -oavc
+ 1> /media/caca/extract/full062011.cpio 2> /media/caca/extract/full_status062011.log
+ find . -depth -path './.*' -prune -o -print
+ [[ -d /media/caca/extract ]]
+ [[ full == incremental ]]
+ echo full
full
Even though I have a 2> /media/caca/extract/full_status$date.log, it is reporting everything like 2>&1 (stderr and stdout). This should only report errors but it not, it reporting everything successfull as well.
??
Last edited by metallica1973; 06-20-2011 at 11:36 AM.
Based on the way you are using -path you could have just used -name and unlike using -path it will also exclude .
The 2> is not acting as 2>&1 otherwise you would see errors as well which you are not getting any.
I suspect it may be something to do with the pipe, but hopefully someone else can give us a better understanding.
You are awesome and thanks for sticking this one out with me. I have one correction. Since I need to be in my home directory when performing find(long story) I had to modify my exclude path from:
Code:
cd $home
. -depth -path "./.*" -prune -o -print
to
Code:
cd $home
. -depth ! -path "./*/.*"
I will test a little bit more before I close the post.
Actually you shouldn't necessarily need to be in home as you could simply pass it to your find:
Here is my answer to your question and why I need the path not to be absolute and it to be relative. I like the flexibility to be able to restore elsewhere instead of the original location.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.