If I execute a task from terminal it works, but within a script it don't...Why?

80 Views Asked by At

Tried every step from terminal, one by one. And they work, but when I execute

cat $dj_name | grep -Eo "(https)://[a-zA-Z0-9./?=_%:-]*.mp3*" | sort -u > $dj_name-tracks

in a script, the script fails leaving the tracks file empty. Here's the entire script I'm using. Thank you.

#!/bin/bash
echo "Which DJ set are we downloading from hearthis.at? (Find the name right after https://hearthis.at, like /*dj_name*/ and write is EXACTLY)"
read dj_name
mkdir $dj_name
cd $dj_name
wget https://hearthis.at/$dj_name/podcast/ -O $dj_name
cat $dj_name | grep -Eo "(https)://[a-zA-Z0-9./?=_%:-]*.mp3*" | sort -u > $dj_name-tracks
while read a b; do wget --user-agent=Mozilla/5.0 --save-cookies cookies.txt --post-data 'dir="$dir1"=&file="$file1"' --no-check-certificate "$a" "$b"; done > $dj_name-tracks
echo "If no error messages are displayed, you are probably good to go. Enjoy."
exit
1

There are 1 best solutions below

3
Roberto Gonzalez On

Working now, using wget -i directly thus removing loop...Thanks for your tips!

#!/bin/bash
echo "Which DJ set are we downloading from hearthis.at? (Find the name right after https://hearthis.at, like /*dj_name*/ and write it EXACTLY)"
read "dj_name"
mkdir "$dj_name"
cd "$dj_name"
wget https://hearthis.at/$dj_name/podcast/ -O "$dj_name"
cat "$dj_name" | grep -Eo "(https)://[a-zA-Z0-9./?=_%:-]*.mp3*" | sort -u > "$dj_name-tracks"
wget --user-agent=Mozilla/5.0 --save-cookies cookies.txt --post-data 'dir="$dir1"=&file="$file1"' --no-check-certificate -i "$dj_name-tracks"
echo "If no error messages are displayed, you are probably good to go. Enjoy."