linux - how to store result of tail command in variable? -
i developing application in mean stack. want create script of image resizing & cropping background process when new image uploads server.
script watches new image uploads in folder , crop it.
i preferred way of linux shell scripting daemon.
i have used following idea accomplished tasks. - new image uploads on server writes in photolog.txt file, can grab images line line. - read photolog.txt in watch.sh shell scripting file. - iterates through line line, until reaches eol. - again new file arrives append @ eol. - manage updated file tail command, , latest add file display in command-line. upto code works charm.
now grab image list of newly added file on server. main issue fails store output of tail command in variable, , must me because whatever output full path of filename , use in imagemagick crop command.
imagemagick center crop scale image.
convert -define file-type:size=widthxheight original_filename -thumbnail 120x120^ -gravity center -extent 100x100 resize_filename
watch.sh
#!/bin/bash path="/var/www/html/appbite/trunk/photolog.txt" cat $path | \ until false # if file exists if [[ -f "$path" ]] while ifs= read -r photo imageformat=`identify $photo | awk '{print $2}'` imagescale=`identify $photo | awk '{print $3}'` echo "$photo $imageformat $imagescale" done fi # continous monitor file changes via commandline tail -f $path done
i grab command-line output not able store value in variable, next use imagemagick image processing command.
or suggest me other way continuous monitoring folder newly added file list.
since tail -f
doesn't terminate, don't want capture output in variable. since call in loop anyway, call on , on this:
out=`tail "$path"`
or using modern syntax:
out=$(tail "$path")
Comments
Post a Comment