Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




4447 posts

Uber Geek
+1 received by user: 685

Trusted

# 39304 12-Aug-2009 13:20
Send private message

Hi

I have the following script which works for me pretty well:


outputpath=/media/aragornvideos/PSP/
if [ -z $@ ]
then
echo "No argument"
exit
fi

show=$@
echo Looking for files in "/media/recordings/$show"
echo Looking for files in "/media/recordings/$show" >> updatepodcasts.log
ls /media/recordings/$show/*
for file in "/media/recordings/$show/*"; do
        if [ -f $file ] ; then
                filenopath=${file##*/}
echo "converting $outputpath$show/$filenopath.mp4" >> updatepodcasts.log
sleep 10
                #handbrake command
                ./HandBrakeCLI -i $file -o $outputpath$show/$filenopath.mp4 --preset "PSP"
                rm $file

        sleep 10
        fi
done
# ls /media/aragornvideos/PSP/* | while read filename; do mv "$filename" `echo "$filename"|sed 's/\.ts//'`;done
sleep 10
#remove files older than 9 days
echo "removing old files" >> updatepodcasts.log
find $outputpath$show/ -type f -mtime +9 -exec rm {} \;
echo "finished processing $show" >> updatepodcasts.log

Basically it grabs from the input directory, converts a file to PSP format and stick it on another machine.
Usually I call it with ./hbfriends Friends
So it goes to the /media/recordings/Friends directory and grabs all the recorded friends episodes.

Well now I'd like to add 3rd Ropck from the Sun to it as well.

I've tried ./hbfriends 3rd\ Rock\ From\ The\ Sun and this doesn't work, and yet I can type ls 3rd\ Rock\ From\ The\ Sun and this will bring back a file name.

Any help appreciated....





Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Create new topic
Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 245673 12-Aug-2009 16:08
Send private message

Use ./hbfriends "3rd Rock From The Sun"




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown



4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 245726 12-Aug-2009 17:55
Send private message

magu: Use ./hbfriends "3rd Rock From The Sun"


Thanks for the reply. Tried that and get the following:
ls: cannot access /media/recordings/3rd: No such file or directory
ls: cannot access Rock: No such file or directory
ls: cannot access From: No such file or directory
ls: cannot access The: No such file or directory
ls: cannot access Sun/*: No such file or directory





Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


 
 
 
 


Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 245750 12-Aug-2009 18:43
Send private message

Hold on... re-writing.




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown

Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 245759 12-Aug-2009 18:53
Send private message

OK, better coded for clearer understanding:

#!/bin/bash
if [ $# -lt 1 ]; then
    echo "No argument."
    exit 1
fi

OUTPUTPATH=/media/aragornvideos/PSP
SHOW=$1

echo "Looking for files in /media/recordings/${SHOW}..." >> updatepodcasts.log
ls "/media/recordings/${SHOW}/*" # this looks like debug info

for file in "/media/recordings/${SHOW}/*"; do
    if [ -f $file ]; then
        FILENAME=${file##*/}
        echo "Converting ${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" >> updatepodcasts.log
        sleep 10
        # handbrake command
        ./HandBrakeCLI -i "$file" -o "${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" --preset "PSP"
        rm $file
        sleep 10
    fi
done

# ls /media/aragornvideos/PSP/* | while read filename; do mv "$filename" `echo "$filename"|sed 's/\.ts//'`;done
sleep 10

# Remove files older than 9 days
echo "Removing old files..." >> updatepodcasts.log
find "${OUTPUTPATH}/${SHOW}"/ -type f -mtime +9 -exec rm {} \;

echo "Finished processing ${SHOW}." >> updatepodcasts.log




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown



4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 245767 12-Aug-2009 19:16
Send private message

Hmm thanks for the rewrite, yes the ls blah blah is debug.

I've tried with: ./hb "3rd\ Rock\ From\ The\ Sun"
and with ./hb 3rd\ Rock\ From\ The\ Sun
and ./hb "3rd Rock From The Sun"

Still no joy.

Any other ides?




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 245780 12-Aug-2009 19:48
Send private message

Can you post the full output?




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown



4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 245804 12-Aug-2009 20:52
Send private message

magu: Can you post the full output?


notroot@Frodo:~$ ./hb "3rd\ Rock\ From\ The\ Sun"
ls: cannot access /media/recordings/3rd\ Rock\ From\ The\ Sun/*: Invalid argument
File found /media/recordings/3rd\ Rock\ From\ The\ Sun/*
./hb: line 16: [: too many arguments

the "file found" is from me adding the line echo File found $file to the line after the for loop





Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


 
 
 
 


Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 245828 12-Aug-2009 21:31
Send private message

Let's clear this out: you have to call the script ./hb "3rd Rock From The Sun"

No \ or anything else.

Another attempt, now with extra 'echo's for debugging. Try running it with the command-line above and post the full output (including ls).

#!/bin/bash
if [ $# -lt 1 ]; then
    echo "No arguments."
    exit 1
fi

OUTPUTPATH=/media/aragornvideos/PSP
SHOW=$1

echo "Looking for files in /media/recordings/${SHOW}..." >> updatepodcasts.log
ls "/media/recordings/${SHOW}" # this looks like debug info

for file in $( ls "/media/recordings/${SHOW}" ); do
    if [ -f $file ]; then
        FILENAME=${file##*/}
        echo "Converting ${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" >> updatepodcasts.log
        # handbrake command
        echo ./HandBrakeCLI -i "$file" -o "${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" --preset "PSP"
        rm $file
        sleep 10
    fi
done

# Remove files older than 9 days
echo "Removing old files..." >> updatepodcasts.log
echo find "${OUTPUTPATH}/${SHOW}"/ -type f -mtime +9 -exec rm {} \;

echo "Finished processing ${SHOW}." >> updatepodcasts.log
exit 0




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown



4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 245843 12-Aug-2009 21:58
Send private message

magu: Let's clear this out: you have to call the script ./hb "3rd Rock From The Sun"

No \ or anything else.

Another attempt, now with extra 'echo's for debugging. Try running it with the command-line above and post the full output (including ls).


First attempt:
notroot@Frodo:~$ ./hb "3rd Rock From The Sun"
ls: cannot access /media/recordings/3rd Rock From The Sun/*: No such file or directory
File found /media/recordings/3rd Rock From The Sun/*
./hb: line 16: [: too many arguments
find: `/media/aragornvideos/PSP/3rd Rock From The Sun/': No such file or directory



#!/bin/bash
if [ $# -lt 1 ]; then
    echo "No arguments."
    exit 1
fi

OUTPUTPATH=/media/aragornvideos/PSP
SHOW=$1

echo "Looking for files in /media/recordings/${SHOW}..." >> updatepodcasts.log
ls "/media/recordings/${SHOW}" # this looks like debug info

for file in $( ls "/media/recordings/${SHOW}" ); do
    if [ -f $file ]; then
        FILENAME=${file##*/}
        echo "Converting ${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" >> updatepodcasts.log
        # handbrake command
        echo ./HandBrakeCLI -i "$file" -o "${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" --preset "PSP"
        rm $file
        sleep 10
    fi
done

# Remove files older than 9 days
echo "Removing old files..." >> updatepodcasts.log
echo find "${OUTPUTPATH}/${SHOW}"/ -type f -mtime +9 -exec rm {} \;

echo "Finished processing ${SHOW}." >> updatepodcasts.log
exit 0


Second one with the new script:

notroot@Frodo:~$ ./hb2 "3rd Rock From The Sun"
3rd Rock From The Sun_20090808_13001400.ts
find /media/aragornvideos/PSP/3rd Rock From The Sun/ -type f -mtime +9 -exec rm {} ;
notroot@Frodo:~$




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 246039 13-Aug-2009 14:42
Send private message

Cool, seems like it should work then, with this non-debug version:


#!/bin/bash
if [ $# -lt 1 ]; then
    echo "No arguments."
    exit 1
fi

OUTPUTPATH=/media/aragornvideos/PSP
SHOW=$1

echo "Looking for files in /media/recordings/${SHOW}..." >> updatepodcasts.log
for file in `ls "/media/recordings/${SHOW}"`; do
    if [ -f $file ]; then
        FILENAME=${file##*/}
        "Converting ${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" >> updatepodcasts.log
        # handbrake command
        ./HandBrakeCLI -i "$file" -o "${OUTPUTPATH}/${SHOW}/${FILENAME}.mp4" --preset "PSP"
        rm $file
        sleep 10
    fi
done

# Remove files older than 9 days
echo "Removing old files..." >> updatepodcasts.log
find "${OUTPUTPATH}/${SHOW}"/ -type f -mtime +9 -exec rm {} \;

echo "Finished processing ${SHOW}." >> updatepodcasts.log
exit 0




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown



4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 246058 13-Aug-2009 15:16
Send private message

hmm not quite sorry. The debug one just spat out the find string at the end.

I updated the hb2 (the debug one) and put the "echo "Filename " $file in after the for loop and got the following output:

notroot@Frodo:~$ ./hb2 "3rd Rock From The Sun"
3rd Rock From The Sun_20090808_13001400.ts
Filename 3rd
Filename Rock
Filename From
Filename The
Filename Sun_20090808_13001400.ts
find /media/aragornvideos/PSP/3rd Rock From The Sun/ -type f -mtime +9 -exec rm {} ;

So looks like it's getting to the if [ -f $file ] and deciding it's not a file.




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex




4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 246063 13-Aug-2009 15:26
Send private message

I removed the If [-f.... and it gets to the echo statements.


Still thinks the filename it's playing with is called "3rd"

notroot@Frodo:~$ ./hb2 "3rd Rock From The Sun"
3rd Rock From The Sun_20090808_13001400.ts
Filename 3rd
-i /media/recordings/3rd Rock From The Sun/3rd -o /media/aragornvideos/PSP/3rd Rock From The Sun/3rd.mp4 --preset




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex




4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 246067 13-Aug-2009 15:32
Send private message

GOT IT.....

Found this:
http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html

Basically resets the delimiter list used by for loops to remove the space and only look for /n




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex




4447 posts

Uber Geek
+1 received by user: 685

Trusted

  # 246070 13-Aug-2009 15:34
Send private message

Thanks for all your help btw!!




Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


Professional yak shaver
1599 posts

Uber Geek
+1 received by user: 8

Trusted
BitSignal
Lifetime subscriber

  # 246077 13-Aug-2009 15:39
Send private message

No worries.




"Roads? Where we're going, we don't need roads." - Doc Emmet Brown

Create new topic



Twitter and LinkedIn »



Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Dunedin selects Telensa to deliver smart street lighting for 15,000 LEDs
Posted 18-Jul-2019 10:21


Sprint announces a connected wallet card with built-in IoT support
Posted 18-Jul-2019 08:36


Educational tool developed at Otago makes international launch
Posted 17-Jul-2019 21:57


Symantec introduces cloud access security solution
Posted 17-Jul-2019 21:48


New Zealand government unveils new digital service to make business easier
Posted 16-Jul-2019 17:35


Scientists unveil image of quantum entanglement
Posted 13-Jul-2019 06:00


Hackers to be challenged at University of Waikato
Posted 12-Jul-2019 21:34


OPPO Reno Z now available in New Zealand
Posted 12-Jul-2019 21:28


Sony introduces WF-1000XM3 wireless headphones with noise cancellation
Posted 8-Jul-2019 16:56


Xero announces new smarter tools, push into the North American market
Posted 19-Jun-2019 17:20


New report by Unisys shows New Zealanders want action by social platform companies and police to monitor social media sites
Posted 19-Jun-2019 17:09


ASB adds Google Pay option to contactless payments
Posted 19-Jun-2019 17:05


New Zealand PC Market declines on the back of high channel inventory, IDC reports
Posted 18-Jun-2019 17:35


Air New Zealand uses drones to inspect aircraft
Posted 17-Jun-2019 15:39


TCL Electronics launches its first-ever 8K TV
Posted 17-Jun-2019 15:18



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.