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.


davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


Create new topic
magu
Professional yak shaver
1599 posts

Uber Geek

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



davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


magu
Professional yak shaver
1599 posts

Uber Geek

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



magu
Professional yak shaver
1599 posts

Uber Geek

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

davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


magu
Professional yak shaver
1599 posts

Uber Geek

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

davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


 
 
 

Move to New Zealand's best fibre broadband service (affiliate link). Free setup code: R587125ERQ6VE. Note that to use Quic Broadband you must be comfortable with configuring your own router.
magu
Professional yak shaver
1599 posts

Uber Geek

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

davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


magu
Professional yak shaver
1599 posts

Uber Geek

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

davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


davidcole

6037 posts

Uber Geek

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

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


davidcole

6037 posts

Uber Geek

Trusted

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

Thanks for all your help btw!!




Previously known as psycik

Home Assistant: Gigabyte AMD A8 Brix, Home Assistant with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Shelly Humidity and Temperature sensors
Media:Chromecast v2, ATV4 4k, ATV4, HDHomeRun Dual
Server
Host Plex Server 3x3TB, 4x4TB using MergerFS, Samsung 850 evo 512 GB SSD, Proxmox Server with 1xW10, 2xUbuntu 22.04 LTS, Backblaze Backups, usenetprime.com fastmail.com Sharesies Trakt.TV Sharesight 


magu
Professional yak shaver
1599 posts

Uber Geek

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





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

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



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.