User Controls
I need to step up my Bash game.
-
2016-07-15 at 6:35 PM UTCBleh thought i was doing a good job suppose not. Any help would be appreciated.
#!/bin/bash
dir="/home/backup/tmp"
echo "Move files?"
read -p 'Y/n? : ' choice
if [ "$choice" == "Y" ]
then
mkdir -p /home/backup/tmp
sudo find / -name cp.* >> /tmp/bla.txt
list="/tmp/bla.txt"
cat $list | xargs -I % bash -c 'mv % -t /home/backup/tmp' && rm -f $list;
cd $dir
for i in $dir
do `clzip --fast`
done
exit 1
else
echo "Exiting..."
exit 0
fi
Move files?
Y/n? : Y
mkdir: cannot create directory ‘/home/backup/tmp’: No such file or directory
find: paths must precede expression: cp.rar
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
./noice.sh: line 10: =/tmp/bla.txt: No such file or directory -
2016-07-18 at 11:58 PM UTCDoes /home/backup exist? If not use mkdir -p
-
2016-07-19 at 12:33 AM UTC
Does /home/backup exist? If not use mkdir -p
Thanks for the reply i may also tweak the "find" operation a little. -
2016-07-19 at 12:33 AM UTC
See the comments "# !!", I don't have clzip, but I assume that portion will work. You fucked up a bunch of basics, but good on the find and xargs stuff I never keep that straight.
#!/bin/bash
# !! nigga it's hash bang not bang hash
# !! don't use $ when assigning
dir="/home/backup/tmp"
echo "Move files?"
read -p 'Y/n? : ' choice
if [ "$choice" == "Y" ]
then
# !! make parent dirs too
mkdir -p /home/backup/tmp
# !! remove backtick (don't know if this matters) and quote the find string (you sick fuck)
sudo find / -name 'cp.*' >> /tmp/bla.txt
# !! don't use $ when assigning and use quotes
list='/tmp/bla.txt'
# you already mv'ed everything in list, just rm $list
cat $list | xargs -I % bash -c 'mv % -t /home/backup/tmp' && rm -f $list;
cd $dir
for i in $dir
do `clzip --fast`
done
exit 1
else
echo "Exiting..."
exit 0
fi -
2016-07-19 at 12:37 AM UTCAlso Lanny plz halp, I can't make a new thread:
That action could not be completed. Please try again, and if this occurs again please contact the system administrator and tell them how you got this message.
-
2016-07-19 at 12:49 AM UTC
Also Lanny plz halp, I can't make a new thread:
That action could not be completed. Please try again, and if this occurs again please contact the system administrator and tell them how you got this message.
Sorry the shebang line was a typo. Also good point about the dollar sign, I know some bash, but it's been ages since i wrote a shellscript. I'm much better with python TBH. -
2016-07-19 at 1:14 AM UTC
Sorry the shebang line was a typo. Also good point about the dollar sign, I know some bash, but it's been ages since i wrote a shellscript. I'm much better with python TBH.
Yeah bash syntax always feels off. It's a good brain exercise to switch around I guess.