LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2018, 09:51 AM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
here's a brain teaser, for some. bash output to current dir, how to redirect it?


I got a script that where ever it is ran this is the output to lame or flac, then it picks up the file in that dir and moves it accordingly. If I am not in the same dir that the script is when I start the script from the cli, then the output is where ever current dir is. therefore, screwing up the code telling it where to get the final product from lame so I can move it accordingly.

wmbutton, I set one button up to call the script to be stared in a terminal, forgetting about that part (above) until I seen it's output file not found.


I could not find how to get a terminal to change into a dir when being started.
Code:
Eterm/xterm/uxterm -e "cd /some other dir"
Eterm/xterm/uxterm -c "cd /some other dir"
does not work, but of course this does.
Code:
Eterm -e "/media/data1/scripts/resample_newMusic" &
but the dir is my home dir that is being used to dump my files into because that is where the script shell is started in, and not the dir the script is actually in.

therefore in order to get my script to know where they are at at all times, due to depending on where or how I start that script. what means would I use to do that?

can it be done?

Code:
#!/bin/bash
script_dir=/media/data1/scripts/
working_dir="/media/data1/music-files-to-do"
move_to=/media/ntfs1/done1-Music

if [[ -d /run/media/userx/3TB-External ]] ; then
{
    copy_to=/run/media/userx/3TB-External/done1-Music
}
elif [[ -d /media/userx/3TB-External ]] ; then
{
    copy_to=/media/userx/3TB-External/done1-Music
}
fi

no_tags=/media/ntfs1/music.No.Tags

if [[ ! -d "${copy_to%/*}" ]] ; then
  echo "drive $copy_to not mounted"
 exit
fi

count="$(find "$working_dir" -type f -iname "*.mp3" -o -iname "*.flac"  | wc -l)"

while read f ; do 

	d=$f
	path=${d%/*}
	name=${d##*/}
	filename=${name%.*}
	ext=${name##*.}
	
    newFile="$filename"."mp3"
    
	newDirStruct=${path/$working_dir/$move_to}
	newCopyTo=${path/$working_dir/$copy_to}
	NoTags=${path/$working_dir/$no_tags}
    
    echo
    echo "$((count--)) :Left:"
    echo
    
    bitrate="$(exiftool -p '$AudioBitrate' "$f")"
    #strips kpbs
    bitrate=${bitrate% *}
    echo "$bitrate"
  
    artist="$(exiftool -p '$Artist' "$f")"
    album="$(exiftool -p '$Album' "$f")"
    title="$(exiftool -p '$Title' "$f")"
    genre="$(exiftool -p '$Genre' "$f")"
    
#changed to Meta Tag info dir structure

    move_new="$move_to"/"$artist"/"$album"
    copy_new="$copy_to"/"$artist"/"$album"


##############################################################
# Resampling with LAME 99.9.5  
# if MP3 is out of limits then re-sample it if not then send it through
# skip resampling saves time
###
# flac -cd "$f" | lame -b 320 - "${f%.*}".mp3
if [[ "${ext}" == 'flac' ]] ; then
{	
4	flac -cd "$f" | lame -V 5 -b 128  -F --vbr-new -m j -q 2  - "$newFile"
         
    rm -v "$f"
        
    bitrate="$(exiftool -p '$AudioBitrate' "$script_dir"/"$newFile")"
    #strips kpbs
    bitrate=${bitrate% *}
    echo ":BiTRATE:2 is :: $bitrate"
        mid3v2 -a "$artist"  "$script_dir"/"$newFile"
        mid3v2 -A "$album"  "$script_dir"/"$newFile"
        mid3v2 -t "$title"  "$script_dir"/"$newFile"
        mid3v2 -g "$genre" "$script_dir"/"$newFile"
        
        artistAlbum="$artist"/"$album"
        
        if [[ -n "$artist" && -n "$album" ]] ; then
       { 
			
			mkdir -p "$move_new"
			mkdir -p "$copy_new"
			
			cp -r "$script_dir"/"$newFile" "$copy_new"  
			mv -vf "$script_dir"/"$newFile" "$move_new"      
        }
        else
        {
            mkdir -p "$NoTags"
            mv -vf "$script_dir"/"$newFile" "$NoTags"          
        }
        fi
} # if  start bitrate  <    128     or   start bitrate > 160 then resample
elif [[ "${bitrate%.*}" -gt "${rate2h}" ]] ; then
{
	lame -V 5 -b 128  -F --vbr-new -m j -q 2 "$f" "$newFile"
    
	rm -v "$f"
	bitrate="$(exiftool -p '$AudioBitrate' "$script_dir"/"$newFile")"
    #strips kpbs
    bitrate=${bitrate% *}
    echo ":BiTRATE:2 is :: $bitrate"
    mid3v2 -a "$artist"  "$script_dir"/"$newFile"
    mid3v2 -A "$album"  "$script_dir"/"$newFile"
    mid3v2 -t "$title"  "$script_dir"/"$newFile"
    mid3v2 -g "$genre" "$script_dir"/"$newFile"
    
    if [[ -n "$artist" && -n "$album" ]] ; then
    {   
		mkdir -p "$move_new"
		mkdir -p "$copy_new"
		
		cp -vr "$script_dir"/"$newFile" "$copy_new"  
		mv -vf "$script_dir"/"$newFile" "$move_new" 
	}
	else
	{
		mkdir -p "$NoTags"
		mv -vf "$script_dir"/"$newFile" "$NoTags"
	}
	fi
} #no resampling needed goes here
elif [[  -n "$artist" && -n "$album" ]] ; then
{
    mkdir -p "$move_new"
	mkdir -p "$copy_new"
			
	cp -vr "$f" "$copy_new"  
	mv -vf "$f" "$move_new" 
  
}
else
{
    mkdir -p "$NoTags"
    mv -vf "$f" "$NoTags"
}
fi

unset album
unset atrist
unset title

done <<<"$(find "$working_dir"  -type f -iname "*.mp3" -o -iname "*.flac" )"
 
Old 11-17-2018, 09:58 AM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by BW-userx View Post
Code:
unset album
unset atrist
unset title
atrist?

Daniel B. Martin

.
 
Old 11-17-2018, 10:02 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Maybe this:
Code:
sh -c 'cd "some other dir"; exec Eterm/xterm/uxterm'
 
Old 11-17-2018, 10:04 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by danielbmartin View Post
atrist?

Daniel B. Martin

.
damn it, someone keeps changing my keys on my KB!!!
thanks for the catch!
 
Old 11-17-2018, 10:12 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by NevemTeve View Post
Maybe this:
Code:
sh -c 'cd "some other dir"; exec Eterm/xterm/uxterm'
that is too simple, let me give that a try.
Nope it does not change the dir path in mine. did you give it a try?
 
Old 11-17-2018, 10:22 AM   #6
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Ok I got it figured out, I added this to the first line of the script .

Code:
#!/bin/bash

cd /media/data1/scripts
I was thinking it had to be more complected, this worked.
 
  


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
copying files from home dir to another dir from another dir in a lower dir chomito44 Linux - General 5 10-19-2013 06:18 PM
LXer: Brain Teaser: Seemingly Random Number List Selection LXer Syndicated Linux News 0 09-10-2008 11:41 AM
pcmcia support - no DISK DRIVE! brain teaser 5185noss Linux - Software 5 08-29-2006 04:08 AM
Brain Teaser for Queen Mary CS Degree Entry Q*Bert General 12 03-03-2003 01:11 AM
Brain Teaser from Queen's College, London Q*Bert General 0 03-01-2003 03:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:05 AM.

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