Releases uploads every time to url like
https://github.com/ipfs/go-ipfs/releases/tag/v0.9.1
my script is
#!/bin/bash
rm /home/ipfs/go-ipfs -rf
rm go-ipfs.tar.gz
curl -s https://api.github.com/repos/ipfs/go-ipfs/releases/latest | grep linux-amd64.tar.gz\" | grep download | sed 's/.*: \"//g' | sed 's/\"//g' | wget -i - -O /home/ipfs/go-ipfs.tar.gz
if test -f /home/ipfs/go-ipfs.tar.gz then
tar -xf /home/ipfs/go-ipfs.tar.g
newsize=$(wc -c <"/home/ipfs/go-ipfs/ipfs")
cursize=$(wc -c <"/home/ipfs/ipfs")
if [$newsize -ne $cursize]; then
mv /home/ipfs/go-ipfs/ipfs /home/ipfs/ipfs
chmod +x /home/ipfs/ipfs
pkill ipfs
fi
fi
but it has an error i cant fix
Solution is
#!/bin/bash
#remove old repo folder
rm /home/ipfs/go-ipfs -rf
#remove old tar.gz
rm go-ipfs.tar.gz
#try to download new
curl -s https://api.github.com/repos/ipfs/go-ipfs/releases/latest | grep linux-amd64.tar.gz\" | grep download | sed 's/.*: \"//g' | sed 's/\"//g' | wget -i - -O /home/ipfs/go-ipfs.tar.gz
#check file exists
if [ -f /home/ipfs/go-ipfs.tar.gz ]; then
#unpack tar gz
tar -xf /home/ipfs/go-ipfs.tar.gz
#get file sizes
newsize=$(wc -c <"/home/ipfs/go-ipfs/ipfs")
cursize=$(wc -c <"/home/ipfs/ipfs")
#if new file is not as current
if (($newsize != $cursize)); then
#replace it
mv /home/ipfs/go-ipfs/ipfs /home/ipfs/ipfs
chmod +x /home/ipfs/ipfs
#kill old to restart new
pkill ipfs
fi
fi
I'm using xubuntu with xfc4, for pure fun I tried to make a script which allows me to put a gif as a desktop wallpaper because this is not a default feature in xfce4.
I've already made a script which seem to work pretty fine excepted that the CPU get in a great trouble with it. So is there a way to optimize this code to do the same thing but stay friend with my CPU?
BG_GIF=/home/grasteau/Pictures/walpapper.gif
DURATION=$(exiftool -Duration walpapper.gif | sed 's/ //g' | sed 's/Duration://g' | sed 's/s//g')
PATH_IMAGE=/
mkdir -p /dev/shm/background
rm -f /dev/shm/background/*
gm convert $BG_GIF +adjoin /dev/shm/background/target%d.png
NUMBER_OF_FRAME=$(bc <<< "$(ls -1 /dev/shm/background | wc -l) - 1")
DELAY=$(bc <<< "scale=3; $DURATION/$NUMBER_OF_FRAME")
while true
do
for i in $(seq 0 $NUMBER_OF_FRAME);
do
PATH_IMAGE="/dev/shm/background/target$i.png"
xfconf-query -c xfce4-desktop -l | grep "last-image$" | while read -r line
do
xfconf-query -c xfce4-desktop -p $line -s $PATH_IMAGE
done
sleep $DELAY
done
done
I am trying to automate a procedure where the system will fetch the contents of a file (1 Url per line), use wget to grab the files from the site (https folder) and then remove the line from the file.
I have made several tries but the sed part (at the end) cannot understand the string (I tried escaping characters) and remove it from that file!
cat File
https://something.net/xxx/data/Folder1/
https://something.net/xxx/data/Folder2/
https://something.net/xxx/data/Folder3/
My line of code is:
cat File | xargs -n1 -I # bash -c 'wget -r -nd -l 1 -c -A rar,zip,7z,txt,jpg,iso,sfv,md5,pdf --no-parent --restrict-file-names=nocontrol --user=test --password=pass --no-check-certificate "#" -P /mnt/USB/ && sed -e 's|#||g' File'
It works up until the sed -e 's|#||g' File part..
Thanks in advance!
Dont use cat if it's posible. It's bad practice and can be problem with big files... You can change
cat File | xargs -n1 -I # bash -c
to
for siteUrl in $( < "File" ); do
It's be more correct and be simpler to use sed with double quotes... My variant:
scriptDir=$( dirname -- "$0" )
for siteUrl in $( < "$scriptDir/File.txt" )
do
if [[ -z "$siteUrl" ]]; then break; fi # break line if him empty
wget -r -nd -l 1 -c -A rar,zip,7z,txt,jpg,iso,sfv,md5,pdf --no-parent --restrict-file-names=nocontrol --user=test --password=pass --no-check-certificate "$siteUrl" -P /mnt/USB/ && sed -i "s|$siteUrl||g" "$scriptDir/File.txt"
done
#beliy answers looks good!
If you want a one-liner, you can do:
while read -r line; do \
wget -r -nd -l 1 -c -A rar,zip,7z,txt,jpg,iso,sfv,md5,pdf \
--no-parent --restrict-file-names=nocontrol --user=test \
--password=pass --no-check-certificate "$line" -P /mnt/USB/ \
&& sed -i -e '\|'"$line"'|d' "File.txt"; \
done < File.txt
EDIT:
You need to add a \ in front of the first pipe
I believe you just need to use double quotes after sed -e. Instead of:
'...&& sed -e 's|#||g' File'
you would need
'...&& sed -e '"'s|#||g'"' File'
I see what you trying to do, but I dont understand the sed command including pipes. Maybe some fancy format that I dont understand.
Anyway, I think the sed command should look like this...
sed -e 's/#//g'
This command will remove all # from the stream.
I hope this helps!
I am trying to use wget in a bash and display a custom download percentage per file so that the user knows the process is running and what has been downloaded. The below seems to download the files but there is no percentage or filename being downloaded displayed. I am not sure why and cannot seem to figure it out. Thank you :).
list
xxxx://www.xxx.com/xxx/xxxx/xxx/FilterDuplicates.html
xxxx://www.xxx.com/xxx/xxxx/xxx/file1.bam
xxxx://www.xxx.com/xxx/xxxx/xxx/file2.bam
xxxx://www.xxx.com/xxx/xxxx/xxx/file1.vcf.gz
xxxx://www.xxx.com/xxx/xxxx/xxx/file2.vcf.gz
bash that uses list to download all fiiles
# download all from list
download() {
local url=$1
echo -n " "
wget --progress=dot $url 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
echo -ne "\b\b\b\b"
echo " starting download"
}
cd "/home/user/Desktop/folder/subfolder"
wget -i /home/cmccabe/list --user=xxx--password=xxx --xxx \
xxxx://www.xxx.com/xxx/xxxx/xxx/ 2>&1 -o wget.log | download
I need to execute the following grep query as an argument for konsole (the kde terminal)
grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R
works for the current terminal.
konsole --workdir `pwd` -e grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R
works, but the konsole window displays the grep query without less pipe.
Ideally I want konsole to spawn as seperate process with konsole &
and send the grep command with less as an argument for konsole -e
You need to run the pipe in a shell.
konsole --workdir pwd -e bash -c 'grep -R -i -n -A 2 -B 2 --color=always -R "searchtext" * | less -R'