LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 02: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, 03:27 PM   #17
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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, 04: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, 04: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, 04:19 AM   #20
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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, 04: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, 04:55 AM   #22
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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, 04:55 AM   #23
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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: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, 05: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, 12:19 PM   #26
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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, 01: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



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 07:55 AM
Quick Bash question for a hosting company webjive Linux - Server 13 12-01-2011 06:47 PM
A quick bash question Ander Linux - Newbie 6 05-05-2006 02:13 AM
Quick bash question neocytrix Programming 8 07-30-2004 10:23 PM
really quick bash question fibbi Linux - Software 3 06-15-2004 10:14 PM

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

All times are GMT -5. The time now is 05:06 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