New Posts  All Forums:Forum Nav:

Bash script help

post #1 of 11
Thread Starter 
So I've noticed that my LG Ally puts GPS data in the picture's EXIF data. This is fine for most things except for when I post pictures to the internet. Facebook is one thing. Sites where I'd like to keep my privacy is another.

Instead of disabling GPS location or going through and naming the tags, I decided to write a script.

There are a few issues though.

First, the script...

Code:
#! /bin/bash

echo 'Where is the file located?'
read location

exif -t 0x0001 --remove $location -o $location

exif -t 0x0002 --remove $location -o $location

exif -t 0x0003 --remove $location -o $location

exif -t 0x0004 --remove $location -o $location

exif -t 0x0005 --remove $location -o $location

exif -t 0x0006 --remove $location -o $location

done
As you can see, it asks for the location of the file. It saves that as "location".

Then it pulls up the program exif and tells it to remove the tag 0x0001 to 0x0006 which are the GPS exif tags. Then it overwrites that file in the same location with the same file name.

This works fine but there are two problems.

1. Autocomplete does not work in bash scripts. On a simple location and file name, this isn't a big deal but if it is "~/pictures/photographs/january3/img93423432.jpg" that's a bunch of typing and I might as well not have a script.

2. I would like to make those 6 exif lines one line but I can't figure out how to do it. I've tried pulling all the tags with "-t 0x0001 0x0002 0x0003". I have tried pulling them separately with "-t 0x0001 -t 0x0002 -t 0x0003" etc. Only way I can get it to work is with 6 lines.

Now what I'd really like to do is make it so I can just do a nautilus action. I can right click and click "GPS Shredder" from the context menu and it will plug the location and file name into the script.
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
post #2 of 11
Thread Starter 
More succinctly...

Suppose I had a file that was ~/Desktop/picture.jpg

How could I make it so I could run gpsshredder.sh ~/Desktop/picture.jpg and it would plug ~/Desktop/picture.jpg into the $location variable?
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
post #3 of 11
What your trying to do is a loop.

I don't know much about bash scripting but I do know about programming.

You should be able to create a for loop for an index and parse your index into your address

add: From a quick search
Code:
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done
That's easy to read

For (( <Variable Decloration> ; <Exit Condition> ; <index modifier>))

What I would try to simply your code is

Code:
#! /bin/bash

echo 'Where is the file located?'
read location

for (( i = 1; i < 7; i++ ))
     exif -t 0x000$i --remove $location -o $location

done
Or something along those lines....see if that works for you. Again, I don't know bash scripting but the basic layout is there. If it's not happy with that, you just need to parse it into an integer or string before you run the command.
Edited by Black Magix - 1/3/11 at 2:24pm
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
post #4 of 11
Thread Starter 
Thanks. I got the loop part done. It's an easy way to apply the script to a file which is the problem.
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
post #5 of 11
Thread Starter 
Alright, so this is what I have with the loop...

Code:
#! /bin/bash

echo 'Where is the file located?'
read location

COUNT=1

while [ $COUNT -lt 7 ]; do
exif -t 0x000$COUNT --remove $location -o $location
let COUNT=COUNT+1
done
Basically what I want to do is imagine my Terminal looking like this:

Code:
$./gpsshred.sh ~/Desktop/image.jpg
And it puts ~/Desktop/image.jpg in for $location
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
post #6 of 11
Thread Starter 
Script complete!

All I needed was "location="$1" and that pulls the variable from the CLI as I run the script.

I also made it a nautilus action so I can just right click on the image and shred the gps information.

Next step is to make it handle batches of files. I guess I'll need to put another loop in there to assign location="$1" to location ="$2" based on the number of files I have selected.
Edited by TFB - 1/3/11 at 6:04pm
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
post #7 of 11
My suggestion would be think a loop within a loop that as long as you enter different locations it will continue to ask for another one.
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
post #8 of 11
I would think more like a b-tree in c++, a recursive loop that calls itself until it can't go any further. If you know c++ you know what I'm talking about, but he finished it =P I just don't know bash, I know c++ though. hahaha I could have written it in c++!
Current Rig
(14 items)
 
  
CPUMotherboardGraphicsRAM
FX-8350 4.6GHz@1.44v GA-990FXA-UD3 R4.0 HD 7950 (1100/1450) 8G Muskin DDR3 1866@8CLS 
Hard DriveOptical DriveOSMonitor
1TB WD LiteOn DVD-RW DL Linux/Windows 19" Phillips TV 1080p 
PowerCaseMouseMouse Pad
OCZ 600W Generic Junk Logitech MX400 Generic Junk 
Audio
SBL 5.1 
  hide details  
Reply
Current Rig
(14 items)
 
  
CPUMotherboardGraphicsRAM
FX-8350 4.6GHz@1.44v GA-990FXA-UD3 R4.0 HD 7950 (1100/1450) 8G Muskin DDR3 1866@8CLS 
Hard DriveOptical DriveOSMonitor
1TB WD LiteOn DVD-RW DL Linux/Windows 19" Phillips TV 1080p 
PowerCaseMouseMouse Pad
OCZ 600W Generic Junk Logitech MX400 Generic Junk 
Audio
SBL 5.1 
  hide details  
Reply
post #9 of 11
I'm up the same alley Mushroom, I could write this in java no problem, no so sure about bash.
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
Nightshade
(20 items)
 
  
CPUMotherboardGraphicsGraphics
i7-4930k Asus Rampage IV Extreme EVGA - Titan-X Superclocked EVGA - Titan-X 
RAMHard DriveHard DriveHard Drive
64 GB Corsair Vengance DDR3 OCZ Agility 3 Intel 540 240GB 7200 RPM Platter Drive 
Hard DriveCoolingOSMonitor
1TB Mushkin SSD Watercooled Windows 10 Pro x64 ASUS ROG Swift 
KeyboardPowerCaseMouse
Razer Black Widow Chroma Corsair RM1000 Corsair 900D Razer Deathadder Chroma 
Mouse PadAudioOther
Steelseries Soundblaster Z Speakers: Logitech z5500 
  hide details  
Reply
post #10 of 11
Thread Starter 
I don't like programming. I barely like scripting.
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Q9550 Gigabyte EP45-UD3P EVGA GTX 465 4x2GB G.Skill 1066 
Hard DriveOSMonitorPower
750GB WD Caviar Black Windows 7 ASUS VW224U Dual Screens Corsair 750w HX 
Case
CM Storm Sniper Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix