LinuxQuestions.org
Help answer threads with 0 replies.
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 05-27-2017, 08:14 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
bash script suddenly stopped working


Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$"\n\b"


picc=( "$1" )
date0=$(stat -c %y "$${picc[0]}" 2>/dev/null | /usr/bin/cut -d. -f1)
dart=${date0//-/}
dart=${dart/ /}
dart2=${dart/:/}
dart=${dart2/:/.}
echo -e "$date0\t$dart"
exit 1
echo "Please enter dimensions (HxV) for ${picc[0]}."
read -e dims
/usr/bin/mogrify -quality 96 -filter lanczos -resize "$dims+0+0!" "${picc[0]}"
/usr/bin/touch -t "$dart" "${picc[0]}"
echo -e "Picture file ${picc[0]} resized to $dims and mod date restored.)"
IFS=$SAVEIFS
It used to apply the "dart" value with touch -t error-free, now it returns an invalid date format error.

I ran Shellcheck on it, corrected a few things it pointed out, and it still gives the error. I suppose Shellcheck doesn;t check for what will work with touch -t in all circumstances.

I'd RTFM, except i find the GNU man-page less than fully informative (haven't read the coreutils info part in a long while, though).

Carver
 
Old 05-27-2017, 08:21 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Have you tried adding
Code:
echo "$dart"
to see what's in there that touch thinks is invalid?
And/or show us what you're passing to the script to populate picc

Last edited by scasey; 05-27-2017 at 08:23 PM.
 
Old 05-27-2017, 09:58 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
IFS=$"\n\b"
I don't think this is specifically your problem, but shouldn't that be
Code:
IFS=$'\n\b'
(also wondering why you're putting \b in IFS)

Reference:
ANSI-C Quoting
Locale-Specific Translation
 
Old 05-27-2017, 11:37 PM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski
(also wondering why you're putting \b in IFS)
I've tried it without the \b, and in earlier versions of bash it didn't work correctly. I just had bash upgraded from the repos, so I think I may try excluding it again, As for going with single quotes on the
Code:
IFS=$"\n\b"
I may try that, too. Double-quotes with me are reflections of my Cygwin days, and I usually "break" a bash install with them (as with mv and renaming single files) by using them.

Carver
 
Old 05-27-2017, 11:41 PM   #5
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
One is there, the other is unclear.

Quote:
Originally Posted by scasey View Post
Have you tried adding
Code:
echo "$dart"
to see what's in there that touch thinks is invalid?
And/or show us what you're passing to the script to populate picc
Line 12 has an "echo $dart."

And picc is usually it's the name of a JPEG file, such as 310_1000.jpg.

Carver
 
Old 05-27-2017, 11:47 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by L_Carver View Post
Line 12 has an "echo $dart."
Perhaps you'd like to share the output with us?
 
Old 05-27-2017, 11:54 PM   #7
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Wink NPAA

Quote:
Originally Posted by ntubski View Post
Perhaps you'd like to share the output with us?
Sure thing. Next post on this thread, I'll show one.

Side topic: an irony is that the "touch is now broken" script is the one I asked for trimming-down advice here.

Carver
 
Old 05-28-2017, 12:30 AM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Quote:
Originally Posted by L_Carver View Post
Line 12 has an "echo $dart."
Oops!
 
Old 05-30-2017, 05:47 PM   #9
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Angry You'll hate what just happened.

I ran the script, commenting out any "exit0's" I was using to test where the date variable values go missing, and it did not return a touch error.

Here is the script I ran:
Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$'\n'


picc="$1"
date0=$(stat -c %y "$picc" 2>/dev/null | /usr/bin/cut -d. -f1)
echo $date0
dart=${date0//-/}
dart=${dart/ /}
dart2=${dart/:/}
dart=${dart2/:/.}
echo -e "$dart"
#exit 1
echo "Please enter dimensions (HxV) for ${picc[0]}."
read -e dims
/usr/bin/mogrify -quality 96 -filter lanczos -resize "$dims+0+0!" "${picc[0]}"
/usr/bin/touch -t "$dart" "${picc[0]}"
echo -e "Picture file ${picc[0]} resized to $dims and mod date restored.)"
IFS=$SAVEIFS
Which looks about the same as the last one I posted, doesn't it? This one may have a few corrections suggested by Shellcheck and the folks here, but on the whole it's the same script.

So the thing that makes me want to scratch my head is: why did it suddenly start working again?

Carver
 
Old 05-31-2017, 03:24 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
Quote:
Originally Posted by L_Carver View Post
Which looks about the same as the last one I posted, doesn't it? This one may have a few corrections suggested by Shellcheck and the folks here, but on the whole it's the same script.

So the thing that makes me want to scratch my head is: why did it suddenly start working again?
Probably those small corrections mean some real functional changes (as I already told you: a $, a { } or () or \ may significantly change the program flow...)

But you forgot to explain what did you modify exactly, so noone can tell you exactly why.
 
Old 06-10-2017, 05:05 AM   #11
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
A working script now, but another annoyance has cropped up

Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$"\n\b"

picc=$1
if [ -f "$picc" ]; then
if [ ! -z "$TDATE" ]; then
 touch dummy
 touch -t "$TDATE" dummy
 echo "The empty file, dummy, was dated as follows"
 stat -c %y dummy
 touch -r "dummy" "$picc"
 /usr/bin/shred -u dummy
fi
fi
IFS=$SAVEIFS
It works, and in spite of what I said in a previous post about keeping noclobber off, I'd really rather delete the file dummy after the 'touch -r' command copies its date stamp to the target file. It seems now to be unable to do this. I've tried "rm," "/usr/bin/rm,' even invoked shred, and it has made no difference. Then I had the (dumb?) idea to write a script specifically to delete the 'dummy' file from my working directory if it found one. And when I invoked it from the above script, it still didn't work.

Carver
Attached Files
File Type: txt nodummy.txt (91 Bytes, 11 views)

Last edited by L_Carver; 06-10-2017 at 05:06 AM.
 
Old 06-10-2017, 12:51 PM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
did you try set -xv? did you check if rm/shred was really executed?
Again you did not post what you really tried
the -i in the first line is definitely not required.
 
Old 06-10-2017, 01:56 PM   #13
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Quote:
Originally Posted by L_Carver View Post
Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$"\n\b"

picc=$1
if [ -f "$picc" ]; then
##if [ ! -z "$TDATE" ]; then
## touch dummy
## touch -t "$TDATE" dummy
## echo "The empty file, dummy, was dated as follows"
## stat -c %y dummy
## touch -r "dummy" "$picc"
## /usr/bin/shred -u dummy
##fi
   touch "$picc"
fi
IFS=$SAVEIFS
It works, and in spite of what I said in a previous post about keeping noclobber off, I'd really rather delete the file dummy after the 'touch -r' command copies its date stamp to the target file. It seems now to be unable to do this. I've tried "rm," "/usr/bin/rm,' even invoked shred, and it has made no difference. Then I had the (dumb?) idea to write a script specifically to delete the 'dummy' file from my working directory if it found one. And when I invoked it from the above script, it still didn't work.

Carver
Again, I feel compelled to ask: Why use dummy and touch -r at all?
See the edited script above...I commented out (and highlighted) the lines I'm saying are not needed to accomplish the task and added one new line. This will have the effect of setting the timestamp on the file named in $picc to "now", which is what the original script is doing [I'm unable to test this, however, and leave it to the OP to try it out].
Needless to say, that makes the last concern about removing the file dummy moot.
 
Old 06-11-2017, 03:10 AM   #14
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Exclamation Don't take the answer beyond the scope of the question, please.

Quote:
Originally Posted by scasey View Post
Again, I feel compelled to ask: Why use dummy and touch -r at all?
I am trying to preserve the file's original modified time. Logically, the various executables in the ImageMagick 'suite,' for instance, change it when you use them on an image file. I want to return the dates I get on each file (server-side modified dates) because, frankly, I hate seeing 2017 in a file date. That's why I used (at someone else's suggestion) the dummy file and touch -r. The last thing I'd want to do is a simple "touch" since that would as likely as not (by the definition of 'touch,' that likelihood is high) set the file's modification date to a date after January 1 2017 and before December 31 2017, which I absolutely do not want. On those occasions when I do download a file with a 2017 mod date, I go searching for another file that has one from a previous year to "borrow" its date for the "newer" (not always really new, because chances are good I've seen it before this year) picture file.

I simply wanted to know why the script was not creating, using, then deleting the dummy file when I instructed it to. I hardly expected a re-analysis of the whole script. I said it worked to my satisfaction except for this one small new issue, which I thought was a glitch in my coding, and still think so.

Carver
 
Old 06-11-2017, 03:17 AM   #15
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
did you try set -xv? did you check if rm/shred was really executed?
Again you did not post what you really tried
the -i in the first line is definitely not required.
I'm so perfectly UNimpressed by bash 4's so-called error checking I'm disinclined ever to use set -xv again. And every line I used (rm, shred) to delete 'dummy' left it there for the second script to take care of. Lately I've been resorting to this as a workaround:
Code:
autotouch foo.jpg && nodummy
I don't want that second bit to be necessary. I don't think it impossible to delete the dummy file from within the autotouch script once it's been created and used (in the touch -r command).

Carver
 
  


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
googleearth Suddenly Has Stopped Working HaroldWho Slackware 2 10-21-2014 08:48 PM
Touchscreen suddenly stopped working Fa773N_M0nK Linux - Laptop and Netbook 2 12-20-2012 02:56 AM
Printer stopped working suddenly? NightSky Slackware 11 12-26-2008 04:50 AM
vmware suddenly stopped working leupi Linux - Software 7 01-22-2007 08:47 PM
airsnort suddenly stopped working fatrandy13 Linux - Security 1 09-23-2004 08:57 PM

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

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