• Making a randomized filename in bash?
    10 replies, posted
Basically, I'm making a screenshot script, it'll let me drag a rectangle, upload the image and put the URL in my clipboard. Everything is fine, except I can't get the name randomized. I've tried a shit load of stuff... including [code]cat /dev/urandom | tr -cd 'a-zA-Z0-9-_' | head -c 3[/code] But I just get [quote]ben@ben-ubuntu:~/.imageup$ ./window.sh ./window.sh: line 6: /dev/urandom: Permission denied[/quote] Any help? Here's my script [code]#!/bin/bash -e IMGDIR=~/.imageup cd $IMGDIR #IMG=cat /dev/urandom | tr -cd 'a-zA-Z0-9-_' | head -c 3 IMG=$(date +%Y%m%d%H%M%S) EXT=.png ICON="/home/ben/.icons/elementary/places/128/network.svg" scrot -d 0 -b -s -q 1 $IMG$EXT notify-send -i $ICON $IMG$EXT "Captured" HOST="somewhere" USER="somebody" PASSWD="something" ftp -n $HOST <<EOF quote USER $USER quote PASS $PASSWD cd /home/ben/benbrooks.co.uk/img/ put $IMG$EXT EOF echo "http://bbrks.me/i/$IMG$EXT" | xclip -selection clipboard notify-send -i $ICON $IMG$EXT "Uploaded!" #rm $IMG[/code] I need the $IMG randomized, lowercase, uppercase, numbers and - _ (as seen in the /dev/urandom snippet)
try using cut?
Is this what you are trying to do? [code] IMG=</dev/urandom tr -cd 'a-zA-Z0-9-_' | head -c 3 echo $IMG [/code] [B]Edit:[/B] Check my post below for the correct code.
[QUOTE=ers35.;25028668]Is this what you are trying to do? [code] IMG=</dev/urandom tr -cd 'a-zA-Z0-9-_' | head -c 3 echo $IMG [/code][/QUOTE] Not quite. [code]IMG=</dev/urandom tr -cd 'a-zA-Z0-9-_' | head -c 3[/code] Having IMG as that basically does this: [quote]ben@ben-ubuntu:~$ sh ~/.imageup/window.sh CpZ[/quote] And then $IMG doesn't seem to be anything, so the URL that gets put in my clipboard is just "http://bbrks.me/i/".
I think I fixed it. [code] IMG=`cat /dev/urandom | tr -cd 'a-zA-Z0-9-_' | head -c 3` echo "http://bbrks.me/i/$IMG" [/code]
[QUOTE=ers35.;25028900]I think I fixed it. [code] IMG=`cat /dev/urandom | tr -cd 'a-zA-Z0-9-_' | head -c 3` echo "http://bbrks.me/i/$IMG" [/code][/QUOTE] It worked!! [img]http://bbrks.me/i/yqv.png[/img] Thanks :)
By the way, Just in case anybody is using the window script and it won't work via a hotkey. You'll need to add a sleep 0.25; just before the scrot command, else it won't work properly. [img]http://bbrks.me/i/7xs.png[/img]
[QUOTE=rieda1589;25045609]By the way, Just in case anybody is using the window script and it won't work via a hotkey. You'll need to add a sleep 0.25; just before the scrot command, else it won't work properly. [img]http://bbrks.me/i/7xs.png[/img][/QUOTE] My AnyHub script is working fine without it :v:
[QUOTE=Lego399;25046251]My AnyHub script is working fine without it :v:[/QUOTE] Weird... It just captures an empty image if I don't add that sleep.
[code]touch <smash keyboard>[/code]
The proper way would be mktemp
Sorry, you need to Log In to post a reply to this thread.