[x-posted to c.u.shell]
[f-up set to c.u.shell]
On 11/30/2017 03:48 PM, Bit Twister wrote:
>> What do I ls here?
>
> Since you failed to run the indicated commands, continue to waste my
> time and others with noise, I will suggest you ls all of them.
I'm not wasting my time. This script will work soon enough.
>
> Since fred renounces Usenet Netiquette rules. I'll provide any lurkers
> and newbie coders with some tips using fred's script as an example.
in other words, this is bt's script:
>
> Glance at fred's script and this one
> $ cat t
> #!/bin/bash
> #**************************************************
> #* t - test code snippet
> #**************************************************
> export PATH=:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
> set -u
>
> App=$(basename $0)
> Last_subdir=""
> Log_dir="logs"
> Next_subdir=""
> Out_fn=$HOME/$Log_dir/$App.log
> Pic_dir=""
>
> if [ -z "EDITOR" ] ; then # set default file editor
> EDITOR=gedit
> fi
>
> if [ 1 -eq 0 ] ; then
> echo "basename dollar sign zero is" $App
> echo "path is" $Log_dir
> echo "Munged time is" $_perliname
> echo "out fn is " $Out_fn
> echo "Time is $_perliname " >> $Out_fn
> fi # end if [ 1 -eq 0 ]
>
> date > $Out_fn
>
> cd $HOME/Pictures
> touch 11.cam
^^what is creating a file gonna do for you,
when we need a directory? How many times will you
insist on being wrong?
> Last_subdir=$(ls -1 *.cam | tail -1)
^^this so doesn't work
> set -- $(IFS='.' ; echo $Last_subdir)
> let Next_subdir="$1 + 1"
> Pic_dir="$HOME/Pictures/$Next_subdir.cam"
> mkdir --verbose $Pic_dir
> echo "pic dir is $Pic_dir" >> $Out_fn
> if [ 1 -eq 0 ] ; then
> id >> $Out_fn
> mount >> $Out_fn
> journalctl --since "1 minute ago" >> $_out_fn
> fi # end if [ 1 -eq 0 ]
>
> $EDITOR $Out_fn &
>
> exit 0
> #*********** end t ********************************
>
> Note:
> o PATH statement is provided to allow script to run in cron.
> o consistent variable naming convention.
> o all variables used are sorted and have an initial value.
> o code should use an indention rule.
> o subject matter experts can run mine, because it does not have any
> special external code needed to run like fred's does.
> That give you a much better chance of getting a subject matter
> expert to help you solve your problem, by saving/running it.
> o external environment variable EDITOR can be set by anyone who does
> not have gedit installed, or wants to use their own editor.
>
> Other environment variables are
> export EDITOR=geany # default file editor
> export VISUAL=emacs # default command line editor
> export PAGER=less # default file pager
> export SLRN_EDITOR=emacs # default Usenet slrn client editor
>
> Fred's code does not start with an empty log. Each run just appends
> results to previous run.
>
> Notice I used if [ 1 -eq 0 ] ; then
> to prevent blocks of code from running to help speedup locating a bug
> in other sections of code.
>
> That also reduces what you have to look through if you were to run it using
> bash -x script_fn_here
>
> You need to think about failure modes. Current code does not protect
> against creating new *.cam directories if the last directory is empty.
>
> You also need to think order of execution. In this case there is no
> sense doing the mkdir $Pic_dir if camera is not mounted or camera does
> not have any pictures.
>
I'm glad for the criticism, but the case is that I can't write this
without perl so far, and I have a truly uneasy detente between perl and
bash. What's more, I see parts of this script that I want, so I'll thank
him for it. Finally, I think it would be a relief to us all if I got a
pretty print bash capability, but I have not achieved it yet.
I'm looking at the environment on the device itself. This was accidental
output when I used the wrong terminal to investigate the following commands.
$ export pager=less
[still don't know what his does except require keystrokes]
$ man bash
man: can't change directory to
'/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD
card/DCIM/Camera': No such file or directory
man: command exited with status 255: sed -e '/^[[:space:]]*$/{ N;
/^[[:space:]]*\n[[:space:]]*$/D; }' | (cd
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
&& LESS=-ix8RmPm Manual page bash(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e
(END):?pB %pB\%.. (press h for help or q to quit)$PM Manual page bash(1)
?ltline %lt?L/%L.:byte %bB?s/%s..?e (END):?pB %pB\%.. (press h for help
or q to quit)$ MAN_PN=bash(1) pager)
$ /declare builtin
bash: /declare: No such file or directory
$
--------trying significantly different things
Q1) How do I make an alias of this bash command, such that it is
persistent after rebooting?
$ bash /home/bob/1.scripts/
1.zax.sh
basename dollar sign zero is
1.zax.sh
path is /logs
Munged time is 01-16-2018_20-38-42
out fn is /home/bob/logs/01-16-2018_20-38-42.log
Time is 01-16-2018_20-38-42
Gtk-Message: GtkDialog mapped without a transient parent. This is
discouraged.
/home/bob/Desktop/kitty/Room6.JPG /home/bob/Desktop/kitty/Room2.JPG
/home/bob/Desktop/kitty/Room4.JPG /home/bob/Desktop/kitty/Room3.JPG
/home/bob/Desktop/kitty/Room1.JPG /home/bob/Desktop/kitty/Room5.JPG
Orientation: RightTop
exif:Orientation: 6
sh: 1: jpegtran: not found
...
Error : Problem executing specified command
in file '/home/bob/Desktop/kitty/Room5.JPG'
Orientation: RightTop
exif:Orientation: 6
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C021%5D/SD card/DCIM/Camera
today is 2018-01-16
behold your log; stop timer and cat app
-- No entries --
cat:
1.zax.sh: No such file or directory
duration=92
$ cat
1.zax.sh
#!/bin/bash
# reduce-desktop.sh
# modified to make arbitrary path explicit
# and more verbose
# keep a log named by time stamp
set -u
app=${0##*/}
pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log
echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " | tee -a "$out"
TITLE='Reduce JPGs on a path'
VER='0.2'
#Constants
SIZE_LIMIT=640
path_to_pics=/home/bob/Desktop/kitty/
path_to_save=~/Pictures/3.cam/6.resize/
declare -ir SUCCESS=0
declare -ir E_FATAL=1
usage()
{
cat <<EOM
$TITLE v$VER
---------------------------------------------------------------------------
Usage: $(basename $0) [options]
Resize all JPG images on user's desktop to max $SIZE_LIMIT pixel-side
NOTE: requires ImageMagick be installed
-q, --quiet disabled # [ ${QUIET} ] || notify
-h, --help Display this help and exit
-v, --version Output version information and exit
EOM
exit $1
}
# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
echo
usage $1
}
# display script version
version()
{
echo "$app v$VER"
exit $SUCCESS
}
#User confirmation
confirm()
{
MSG="Do you want to autorotate all images on this path $path_to_pics?"
zenity --question --text="$MSG" --title="$TITLE" --display=:0 ||
exit $SUCCESS
}
#User notification
notify()
{
MSG="Images conversion complete"
notify-send "$TITLE" "$MSG" || exit $SUCCESS
}
# Parse command line for options
if (( $# ))
then
case $1 in
-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument"
esac
else
confirm
fi
pics=$(find $path_to_pics -maxdepth 1 -type f -iname "*.jpg" -or -iname
"*.jpeg")
echo $pics
for pic in ${pics[@]}
do
identify -verbose $pic | grep Orientation | tee -a "$out"
/home/bob/Downloads/jhead-3.00/jhead -autorot $pic | tee -a "$out"
identify -verbose $pic | grep Orientation | tee -a "$out"
done
pwd | tee -a "$out"
FROM="/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C020%5D/SD
card/DCIM/Camera"
today=$(date +"%Y-%m-%d")
echo "today is $today" | tee -a "$out"
echo "behold your log; stop timer and cat app" | tee -a "$out"
journalctl --since "30 seconds ago" | tee -a "$out"
gedit $out && read -n 1
cat $app | tee -a "$out"
echo "duration=$SECONDS" | tee -a "$out"
exit $SUCCESS
$
Looking for any constructive criticism for this code. Needs a lot of
editing, I know.
--
fred