LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2011, 06:12 PM   #16
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60

One more little tine issue. It appears that:

Code:
. -depth \( -wholename \./\.\* \) -prune
is being ignored from:

Code:
$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > /media/caca/extract/full$date.cpio 2> /media/caca/extract/full_status$date.log
Code:
$> tail -f /media/caca/extract/full_status061711.log 
./saint/.gconf/apps/evolution/calendar/memos/history_backup
./saint/.gconf/apps/evolution/calendar/memos/npatgpc.dl_
./saint/.gconf/apps/evolution/calendar/memos/typescript
./saint/.gconf/apps/evolution/calendar/memos/xprobe_test_network
./saint/.gconf/apps/evolution/calendar/memos
./saint/.gconf/apps/evolution/calendar/tasks/colors/10.7.X_network
./saint/.gconf/apps/evolution/calendar/tasks/colors/%gconf.xml
./saint/.gconf/apps/evolution/calendar/tasks/colors/bash_history
./saint/.gconf/apps/evolution/calendar/tasks/colors/davmail.log
./saint/.gconf/apps/evolution/calendar/tasks/colors/davmail.log.1
1
but when done from a terminal, it works:

Code:
$> $search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > /media/caca/extract/full$date.cpio
./examples.desktop
./Desktop/saint.desktop
./Desktop
^Z
[21]+  Stopped                 $search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > /media/caca/extract/full$date.cpio
So where am I missing a "" or '' in my script so that it interpets the exclude statement"\( -wholename \./\.\* \) -prune"

?????
 
Old 06-18-2011, 01:37 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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:
Code:
$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > /media/caca/extract/full$date.cpio 2> /media/caca/extract/full_status$date.log
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??
 
Old 06-18-2011, 08:50 AM   #18
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
ok, allow me to clarify.

when I am testing my script I will do so from the terminal to test whether the statement works like:

Code:
~$ archive="cpio -oav"
~$ search=find
~$ backup_dir=/home/davider/Downloads
~$ date=$(date +%m%d%y)
then run the test:

Code:
~$ $search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
then on another terminal I watch my log file to see if my script is doing what it supposed to doing.

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
./Pictures/10_25_2006/ScanImage13.jpg
./Pictures/10_25_2006/ScanImage50.jpg
./Pictures/10_25_2006/ScanImage17.jpg
./Pictures/10_25_2006/ScanImage22.jpg
As you can see from above it works just fine. The statement, is not supposed to copy any of my "hidden" directories thus the

Code:
\( -wholename \./\.\* \) -prune
to exclude:

Code:
drwxr-xr-x 33 davider davider     4096 2011-06-11 20:37 .config
drwxr-xr-x  5 davider davider     4096 2011-02-17 20:40 .cpan
drwxr-xr-x  5 davider davider     4096 2011-02-17 20:11 .cpanplus
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":

Code:
$ ksh -x saint_home.ksh full
+ results=full
+ backup_dir=/home/davider/Downloads
+ date +%m%d%y
+ date=061811
+ search=find
+ archive='cpio -oav'
+ [[ -d /home/davider/Downloads ]]
+ [[ full == full ]]
+ cd /home
+ cpio -oav
+ 1> /home/davider/Downloads/full061811.cpio 2> /home/davider/Downloads/full_status061811.log
+ find . -depth '(' -wholename './.*' ')' -prune -o -print
and my tail -f

Code:
./davider/.local/share/gvfs-metadata/smb-share:server=192.168.3.1,share=caca
./davider/.local/share/gvfs-metadata/uuid-efade6e3-5381-45f7-9983-51be4a5ddcc9
./davider/.local/share/gvfs-metadata/smb-share:server=192.168.3.23,share=shit
./davider/.local/share/gvfs-metadata/uuid-3729-49D6
./davider/.local/share/gvfs-metadata/uuid-72D83879D8383DA3
./davider/.local/share/gvfs-metadata/uuid-0C8E4D518E4D350C-e00d21e8.log
./davider/.local/share/gvfs-metadata/uuid-63D2-4D30
./davider/.local/share/gvfs-metadata/label-Data\x20disc\x20\x2823\x20Jan\x2011\x29
./davider/.local/share/gvfs-metadata/uuid-aa57a5c8-45ae-4a86-9bd9-1c438e2880a1-b2d2e6dd.log
./davider/.local/share/gvfs-metadata/uuid-3729-49D6-87be2bf9.log
./davider/.local/share/gvfs-metadata/uuid-1f792d3e-033f-4013-b651-1a6a4c025e09
./davider/.local/share/gvfs-metadata/gphoto2:host=%5Busb%3A002%2C009%5D-e66c8ecb.log
./davider/.local/share/gvfs-metadata/label-CDROM
as you can see from above "ksh -x" is not interpreting inside "$search" correctly.

Code:
+ find . -depth '(' -wholename './.*' ')' -prune -o -print
it is supposed to interpret as:

Code:
find . -depth \( -wholename \./\.\* \) -prune -o -print
it not seeing any of the "\"

I know it is something simple but I just cannot figure it out. I have tried adding "",'' and etc.

Code:
"$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log"
Code:
$search . -depth "\( -wholename \./\.\* \)" -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log"
I cant figure this one out. ?????????????????????????????????

Last edited by metallica1973; 06-18-2011 at 08:53 AM.
 
Old 06-18-2011, 09:54 AM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So can I confirm something ... your native shell, ie at the command line, this is also ksh?

What happens if you try it this way at the command line:
Code:
~$ set -x
~$ archive="cpio -oav"
~$ search=find
~$ backup_dir=/home/davider/Downloads
~$ date=$(date +%m%d%y)
~$ $search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
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
./Pictures/10_25_2006/ScanImage13.jpg
./Pictures/10_25_2006/ScanImage50.jpg
./Pictures/10_25_2006/ScanImage17.jpg
./Pictures/10_25_2006/ScanImage22.jpg
This is saying these are all the errored items ... so not exactly proof of:
Quote:
As you can see from above it works just fine.
I would disagree and say it is not working as you expect.

Anyhow, try the test i have suggested above to see what is happening when you execute at the command line.
 
Old 06-18-2011, 09:58 PM   #20
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
thanks for the reply again,

grail,

Quote:
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.

Code:
Downloads$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-02-11 10:32 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:28 extract
drwxr-xr-x 3 davider davider     4096 2011-06-18 18:24 vpnclient
:~/Downloads$ ksh -x ../Documents/scripts/saint_home.ksh full
+ results=full
+ backup_dir=/home/davider/Downloads
+ date +%m%d%y
+ date=061811
+ search=find
+ archive='cpio -oacv'
+ [[ -d /home/davider/Downloads ]]
+ [[ full == full ]]
+ cpio -oacv
+ find . -depth '(' -wholename './.*' ')' -prune -o -print
+ 1> /home/davider/Downloads/full061811.cpio 2> /home/davider/Downloads/full_status061811.log
+ [[ -d /home/davider/Downloads ]]
+ [[ full == incremental ]]
+ echo full
full
Downloads$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-02-11 10:32 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:28 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1147 2011-06-18 22:39 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 18:24 vpnclient
Downloads$ mv full061811.cpio extract/
Downloads$ cd extract/
Downloads/extract$ ls -l
total 11876
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
Downloads/extract$ cpio -ivcd < full061811.cpio 
extract
vpnclient/.tmp_versions/cisco_ipsec.mod
vpnclient/.tmp_versions
vpnclient
cpio: full061811.cpio not created: newer or same age version exists
full061811.cpio
ciscovpn/libssl.so.0.9.8
ciscovpn/vpn_install.sh
ciscovpn/update.txt
ciscovpn/vpn
ciscovpn/libcrypto.so.0.9.8
ciscovpn/AnyConnectLocalPolicy.xsd
ciscovpn/manifesttool
ciscovpn/vpnui
ciscovpn/VPNManifestClient.xml
ciscovpn/AnyConnectProfile.xsd
ciscovpn/vpnagentd
ciscovpn/anyconnect.desktop
ciscovpn/license.txt
ciscovpn/vpndownloader
ciscovpn/vpn_uninstall.sh
ciscovpn/vpnagentd_init
ciscovpn/pixmaps/vpnui48.png
ciscovpn/pixmaps/cvc-disconnect.png
ciscovpn/pixmaps/systray_notconnected.png
ciscovpn/pixmaps/systray_connected.png
ciscovpn/pixmaps/cvc-connect.png
ciscovpn/pixmaps/cvc-info.png
ciscovpn/pixmaps/cvc-about.png
ciscovpn/pixmaps/systray_reconnecting.png
ciscovpn/pixmaps/cvc-configure.png
ciscovpn/pixmaps/systray_disconnecting.png
ciscovpn/pixmaps/company-logo.png
ciscovpn/pixmaps/systray_quarantined.png
ciscovpn/pixmaps
ciscovpn/AnyConnectProfile.tmpl
ciscovpn
full_status061811.log
.
23747 blocks
Downloads/extract$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 22:40 vpnclient
Downloads/extract$ ls -l ciscovpn/
total 11896
-rw-rw-r-- 1 davider davider     281 2011-06-18 22:40 anyconnect.desktop
-rw-rw-r-- 1 davider davider    3958 2011-06-18 22:40 AnyConnectLocalPolicy.xsd
-rw-rw-r-- 1 davider davider   15917 2011-06-18 22:40 AnyConnectProfile.tmpl
-rw-rw-r-- 1 davider davider   89714 2011-06-18 22:40 AnyConnectProfile.xsd
-rwxrwxr-x 1 davider davider 1177529 2011-06-18 22:40 libcrypto.so.0.9.8
-rwxrwxr-x 1 davider davider  224171 2011-06-18 22:40 libssl.so.0.9.8
-rw-rw-r-- 1 davider davider    5487 2011-06-18 22:40 license.txt
-rwxrwxr-x 1 davider davider  841425 2011-06-18 22:40 manifesttool
drwxrwxr-x 2 davider davider    4096 2011-06-18 22:40 pixmaps
-rw-rw-r-- 1 davider davider       9 2011-06-18 22:40 update.txt
-rwxrwxr-x 1 davider davider 2575704 2011-06-18 22:40 vpn
-rwxrwxr-x 1 davider davider 2196452 2011-06-18 22:40 vpnagentd
-rw-rw-r-- 1 davider davider    1153 2011-06-18 22:40 vpnagentd_init
-rwxrwxr-x 1 davider davider 2294200 2011-06-18 22:40 vpndownloader
-rwxr-xr-x 1 davider davider    9648 2011-06-18 22:40 vpn_install.sh
-rw-rw-r-- 1 davider davider     249 2011-06-18 22:40 VPNManifestClient.xml
-rwxrwxr-x 1 davider davider 2699148 2011-06-18 22:40 vpnui
-rwxrwxr-x 1 davider davider    4748 2011-06-18 22:40 vpn_uninstall.sh
Downloads/extract$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 22:40 vpnclient
Downloads/extract$ ls -la
total 11900
drwxr-xr-x  5 davider davider     4096 2011-06-18 22:40 .
drwxr-xr-x 47 davider davider     4096 2011-06-18 22:40 ..
drwxrwxr-x  3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x  2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r--  1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r--  1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x  3 davider davider     4096 2011-06-18 22:40 vpnclient
and from the terminal I watch the log file, how odd that the 2> is sending all output to the file like 2>&1 but either way it working:

Code:
Downloads/extract$tail -f full_status061811.log
./extract
./vpnclient/.tmp_versions/cisco_ipsec.mod
./vpnclient/.tmp_versions
./vpnclient
cpio: File ./full061811.cpio grew, 512 new bytes not copied
./full061811.cpio
./ciscovpn/libssl.so.0.9.8
./ciscovpn/vpn_install.sh
./ciscovpn/update.txt
./ciscovpn/vpn
./ciscovpn/libcrypto.so.0.9.8
./ciscovpn/AnyConnectLocalPolicy.xsd
./ciscovpn/manifesttool
./ciscovpn/vpnui
./ciscovpn/VPNManifestClient.xml
./ciscovpn/AnyConnectProfile.xsd
./ciscovpn/vpnagentd
./ciscovpn/anyconnect.desktop
./ciscovpn/license.txt
./ciscovpn/vpndownloader
./ciscovpn/vpn_uninstall.sh
./ciscovpn/vpnagentd_init
./ciscovpn/pixmaps/vpnui48.png
./ciscovpn/pixmaps/cvc-disconnect.png
./ciscovpn/pixmaps/systray_notconnected.png
./ciscovpn/pixmaps/systray_connected.png
./ciscovpn/pixmaps/cvc-connect.png
./ciscovpn/pixmaps/cvc-info.png
./ciscovpn/pixmaps/cvc-about.png
./ciscovpn/pixmaps/systray_reconnecting.png
./ciscovpn/pixmaps/cvc-configure.png
./ciscovpn/pixmaps/systray_disconnecting.png
./ciscovpn/pixmaps/company-logo.png
./ciscovpn/pixmaps/systray_quarantined.png
./ciscovpn/pixmaps
./ciscovpn/AnyConnectProfile.tmpl
./ciscovpn
./full_status061811.log
.
23747 blocks
as you can see all is working well except for the script not interpreting:

Code:
\( -wholename \./\.\* \) -prune
from the script.

Code:
$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
Do I need quotes somewhere? Its killing me!

Last edited by metallica1973; 06-18-2011 at 10:49 PM.
 
Old 06-18-2011, 10:36 PM   #21
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
thanks for the reply again,

grail,

Quote:
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.

Code:
Downloads$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-02-11 10:32 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:28 extract
drwxr-xr-x 3 davider davider     4096 2011-06-18 18:24 vpnclient
:~/Downloads$ ksh -x ../Documents/scripts/saint_home.ksh full
+ results=full
+ backup_dir=/home/davider/Downloads
+ date +%m%d%y
+ date=061811
+ search=find
+ archive='cpio -oacv'
+ [[ -d /home/davider/Downloads ]]
+ [[ full == full ]]
+ cpio -oacv
+ find . -depth '(' -wholename './.*' ')' -prune -o -print
+ 1> /home/davider/Downloads/full061811.cpio 2> /home/davider/Downloads/full_status061811.log
+ [[ -d /home/davider/Downloads ]]
+ [[ full == incremental ]]
+ echo full
full
Downloads$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-02-11 10:32 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:28 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1147 2011-06-18 22:39 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 18:24 vpnclient
Downloads$ mv full061811.cpio extract/
Downloads$ cd extract/
Downloads/extract$ ls -l
total 11876
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
Downloads/extract$ cpio -ivcd < full061811.cpio 
extract
vpnclient/.tmp_versions/cisco_ipsec.mod
vpnclient/.tmp_versions
vpnclient
cpio: full061811.cpio not created: newer or same age version exists
full061811.cpio
ciscovpn/libssl.so.0.9.8
ciscovpn/vpn_install.sh
ciscovpn/update.txt
ciscovpn/vpn
ciscovpn/libcrypto.so.0.9.8
ciscovpn/AnyConnectLocalPolicy.xsd
ciscovpn/manifesttool
ciscovpn/vpnui
ciscovpn/VPNManifestClient.xml
ciscovpn/AnyConnectProfile.xsd
ciscovpn/vpnagentd
ciscovpn/anyconnect.desktop
ciscovpn/license.txt
ciscovpn/vpndownloader
ciscovpn/vpn_uninstall.sh
ciscovpn/vpnagentd_init
ciscovpn/pixmaps/vpnui48.png
ciscovpn/pixmaps/cvc-disconnect.png
ciscovpn/pixmaps/systray_notconnected.png
ciscovpn/pixmaps/systray_connected.png
ciscovpn/pixmaps/cvc-connect.png
ciscovpn/pixmaps/cvc-info.png
ciscovpn/pixmaps/cvc-about.png
ciscovpn/pixmaps/systray_reconnecting.png
ciscovpn/pixmaps/cvc-configure.png
ciscovpn/pixmaps/systray_disconnecting.png
ciscovpn/pixmaps/company-logo.png
ciscovpn/pixmaps/systray_quarantined.png
ciscovpn/pixmaps
ciscovpn/AnyConnectProfile.tmpl
ciscovpn
full_status061811.log
.
23747 blocks
Downloads/extract$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 22:40 vpnclient
Downloads/extract$ ls -l ciscovpn/
total 11896
-rw-rw-r-- 1 davider davider     281 2011-06-18 22:40 anyconnect.desktop
-rw-rw-r-- 1 davider davider    3958 2011-06-18 22:40 AnyConnectLocalPolicy.xsd
-rw-rw-r-- 1 davider davider   15917 2011-06-18 22:40 AnyConnectProfile.tmpl
-rw-rw-r-- 1 davider davider   89714 2011-06-18 22:40 AnyConnectProfile.xsd
-rwxrwxr-x 1 davider davider 1177529 2011-06-18 22:40 libcrypto.so.0.9.8
-rwxrwxr-x 1 davider davider  224171 2011-06-18 22:40 libssl.so.0.9.8
-rw-rw-r-- 1 davider davider    5487 2011-06-18 22:40 license.txt
-rwxrwxr-x 1 davider davider  841425 2011-06-18 22:40 manifesttool
drwxrwxr-x 2 davider davider    4096 2011-06-18 22:40 pixmaps
-rw-rw-r-- 1 davider davider       9 2011-06-18 22:40 update.txt
-rwxrwxr-x 1 davider davider 2575704 2011-06-18 22:40 vpn
-rwxrwxr-x 1 davider davider 2196452 2011-06-18 22:40 vpnagentd
-rw-rw-r-- 1 davider davider    1153 2011-06-18 22:40 vpnagentd_init
-rwxrwxr-x 1 davider davider 2294200 2011-06-18 22:40 vpndownloader
-rwxr-xr-x 1 davider davider    9648 2011-06-18 22:40 vpn_install.sh
-rw-rw-r-- 1 davider davider     249 2011-06-18 22:40 VPNManifestClient.xml
-rwxrwxr-x 1 davider davider 2699148 2011-06-18 22:40 vpnui
-rwxrwxr-x 1 davider davider    4748 2011-06-18 22:40 vpn_uninstall.sh
Downloads/extract$ ls -l
total 11892
drwxrwxr-x 3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x 2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r-- 1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r-- 1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x 3 davider davider     4096 2011-06-18 22:40 vpnclient
Downloads/extract$ ls -la
total 11900
drwxr-xr-x  5 davider davider     4096 2011-06-18 22:40 .
drwxr-xr-x 47 davider davider     4096 2011-06-18 22:40 ..
drwxrwxr-x  3 davider davider     4096 2011-06-18 22:40 ciscovpn
drwxr-xr-x  2 davider davider     4096 2011-06-18 22:40 extract
-rw-r--r--  1 davider davider 12158464 2011-06-18 22:39 full061811.cpio
-rw-r--r--  1 davider davider     1108 2011-06-18 22:40 full_status061811.log
drwxr-xr-x  3 davider davider     4096 2011-06-18 22:40 vpnclient
as you can see all is working well except for the script not interpreting:

Code:
\( -wholename \./\.\* \) -prune
from the script.

Code:
$search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
the shell see's

Code:
find . -depth '(' -wholename './.*' ')' -prune -o -print
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.
 
Old 06-18-2011, 11:19 PM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 06-19-2011, 02:48 PM   #23
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
I forgot to post that information:

Code:
~$ set -x
+ set -x
~$ archive="cpio -oavc"
+ archive='cpio -oav'
~$ search=find
+ search=find
~$ backup_dir=/home/davider/Downloads
+ backup_dir=/home/davider/Downloads
davider@Divine-Gift:~/Documents/scripts$ date=$(date +%m%d%y)
++ date +%m%d%y
+ date=061811
davider@Divine-Gift:~/Documents/scripts$ archive="cpio -oavc"
+ archive='cpio -oavc'
davider@Divine-Gift:~/Documents/scripts$ $search . -depth \( -wholename \./\.\* \) -prune -o -print | $archive > $backup_dir/full$date.cpio 2> $backup_dir/full_status$date.log
+ find . -depth '(' -wholename './.*' ')' -prune -o -print
+ cpio -oavc
It has the same results basically as ksh -x. You can see how it is not interpreting:

Code:
\( -wholename \./\.\* \) -prune
but seeing it as:

Code:
'(' -wholename './.*' ')' -prune
???

Last edited by metallica1973; 06-19-2011 at 02:51 PM.
 
Old 06-19-2011, 07:39 PM   #24
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 06-20-2011, 11:08 AM   #25
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Grail,

Thanks for the reply

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 exampleto 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
which produced the results I was looking for:

Code:
+ find . -depth -path './.*' -prune -o -print
So I finally added that to the script and ran it:

Code:
$search . -depth -path "./.*" -prune -o -print | $archive > /media/caca/extract/full$date.cpio 2> /media/caca/extract/full_status$date.log
on more thing I had to add:

Code:
! -path "./.*"
and take out:

Code:
-prune -o
to exclude my hidden directories in my home directory:

Code:
$search . -depth -mtime -1 ! -path "./.*"  -print | $archive > /media/caca/extract/inc$date.cpio 2> /media/caca/extract/inc$date.log
One more question:

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.
 
Old 06-20-2011, 07:55 PM   #26
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 06-20-2011, 09:52 PM   #27
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Smile

Grail,

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.
 
Old 06-20-2011, 11:37 PM   #28
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Actually you shouldn't necessarily need to be in home as you could simply pass it to your find:
Code:
find $HOME ...
I did have a question for you though ... and it just may be your preference, but is there a reason you are using cpio and not tar? (just curious)
 
Old 06-21-2011, 09:51 PM   #29
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Quote:
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.

http://http://osr507doc.sco.com/en/OSUserG/_Extract_from_cpio_backup.html

as far as cpio vs using tar, orginally I was going to use cpio ...| xargs but later read this article from linuxjournals.com

http://http://www.linuxjournal.com/article/1213

seems to be a better fit.

Last edited by metallica1973; 06-21-2011 at 09:54 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
inputting values into variables for math from the command line? dave247 Linux - General 2 10-22-2010 01:50 PM
[SOLVED] How to access command line variables from awk puth Programming 5 02-12-2010 12:06 PM
how to write command line arguments as values, into a file which contains variables sathiawathi.m Linux - Newbie 2 07-17-2009 02:27 AM
Need a shell scipt to get 2 variables per line and then run a command var 1 is over 5 abefroman Programming 2 02-18-2006 03:46 PM
Scripting : Dual line output into next script as variables facets Programming 6 06-10-2004 02:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration