LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2014, 03:10 PM   #16
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled

Ahh I see... so since we are telling it to do this to all files within the directory, we don't actually need to find the files every time.

That makes perfect sense!! I like it...

I'm going to play around with this idea, I like it a lot..

Thanks so much for your help.
 
Old 06-16-2014, 04:27 PM   #17
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,254

Rep: Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420
Quote:
Originally Posted by jonnybinthemix View Post
so since we are telling it to do this to all files within the directory, we don't actually need to find the files every time.
The benefit of the find command is that is searches through the subdirectories recursively, since everything is in one directory we can use globbing instead which is simpler but less powerful.

We can avoid refinding the files regardless of where they are.
 
1 members found this post helpful.
Old 06-17-2014, 05:13 AM   #18
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
I am trying this out, and it's looking like it could work fine.. but I am struggling to actually get it going. It's moaning;

usage: gpg [options] --encrypt [filename]
local: *170614*.csv.pgp: No such file or directory
-eFTP TRANSFER FAILED. \n\n *170614*.csv.pgp failed to upload to server

Code:
#!/bin/bash

HOST=X.X.X.X
USER=user
PASS=pass
FTPLOG=/tmp/ftplogfile

cd /sitsimp

for i in "*$(date +%d%m%y)*.csv"; do
        gpg -r server@bathspa.ac.uk -e "$i" -o "$i.pgp";

        ftp -inv $HOST <<! > $FTPLOG
                user $USER xxxx
                binary
                put $i.pgp
        bye
!
        if fgrep "226 Transfer Complete" $FTPLOG; then
                echo -e "FTP TRANSFER SUCCESS. \n\n $i.pgp has uploaded to server"
        else
                echo -e"FTP TRANSFER FAILED. \n\n $i.pgp failed to upload to server"
        fi
done
 
Old 06-17-2014, 05:16 AM   #19
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
I have tried moving the "'s around the filename section but I can't seem to make any difference with it.

I've tried
"*$(date +%d%m%y)*.csv" & *$"(date +%d%m%y)"*.csv
 
Old 06-17-2014, 05:19 AM   #20
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,880

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
just insert set -xv at the beginning of the script and you will see what's happening
 
1 members found this post helpful.
Old 06-17-2014, 05:52 AM   #21
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Ah thanks, that's a neat little trick

I can see that it's definitely something to do with the filename... does the for loop not like the * wildcard?

Code:
++ date +%d%m%y
+ for i in '"$(date +%d%m%y)*.csv"'
+ gpg -r server@bathspa.ac.uk -e '170614*.csv' -o '170614*.csv.pgp'
usage: gpg [options] --encrypt [filename]
So it's looking for a file that literally is todays date, not that has todays date in the filename...
 
Old 06-17-2014, 05:55 AM   #22
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,880

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
probably:
Code:
D=$(date +%d%m%y)
for i in $D*.csv
...
but it will fail if there was no such file at all
 
1 members found this post helpful.
Old 06-17-2014, 05:55 AM   #23
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,880

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
probably:
Code:
D=$(date +%d%m%y)
for i in $D*.csv
...
but it will fail if there was no such file at all
 
1 members found this post helpful.
Old 06-17-2014, 06:04 AM   #24
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
I've whittled it down to the command..

I adjusted the file thing and it's now finding the correct file.

When I manually run the following command, it does not work:

Code:
gpg -r server@bathspa.ac.uk -e 170614094401.csv -o 170614094401.csv.pgp
I think it doesn't like being told the name of the output file?
 
Old 06-17-2014, 06:39 AM   #25
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
playing around some more has got me passed this hurdle.. just an issue with FTP now which I'll continue to pick away at.

This seemed to work:

Code:
for i in $(date +%d%m%y)*.csv; do
        gpg -r server@bathspa.ac.uk -o "$i.pgp" -e "$i";
 
Old 06-17-2014, 01:19 PM   #26
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,254

Rep: Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420Reputation: 1420
Note the placement of the quotes. If the * is inside the quotes it doesn't get glob expanded.

Quote:
Originally Posted by ntubski View Post
Code:
for i in *"$(date +%d%m%y)"*.csv; do
Quote:
Originally Posted by jonnybinthemix View Post
Code:
for i in "*$(date +%d%m%y)*.csv"; do
You can omit the quotes entirely, which shouldn't make a difference as long as the date format you're using doesn't have any spaces in it.
 
Old 06-17-2014, 02:53 PM   #27
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Hey,

In fact that's what I ended up doing... omitting the quotes all together, which worked fine. I've now stumbled across another issue relating to the same script which I've started a new thread for, to make searching easier for others
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Quick BASH Question jonnybinthemix Linux - Newbie 2 06-13-2014 08:55 AM
Quick Bash question for a hosting company webjive Linux - Server 13 12-01-2011 07:47 PM
A quick bash question Ander Linux - Newbie 6 05-05-2006 03:13 AM
Quick bash question neocytrix Programming 8 07-30-2004 11:23 PM
really quick bash question fibbi Linux - Software 3 06-15-2004 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:03 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration