I made a bash script which can tree
a whole directory structure recursively, putting into every directory a HTML file generated by the aha
. The script read the list of directories to be indexed. find
search for every directory inside the directory and generate the complete list of directories. If directory /media/veracrypt1
contains 50 directories in the hierarchical structure, tree
makes a tree of everything in the given directory and "below", write the HTML file with the recorded tree structure inside the directory, then goes down, repeat the action down to the bottom.
I would like the script to be fired on the defined time by the cron
. The script works but the colorization does not and the output of the pipe is black on white. I believe it is the result of cron
not having access to the LS_COLOR
system variable. (This is what I suspect)
How to correct the script to make it produce the desired effect?
The vital fragment of the script:
tree -axC "$file" | aha --title $(basename "${file// /_}") > "$file"/[z9][tree]_$(basename "${file// /_}").html; done
It works also without aha
:
tree -axC "$file" > "$file"/[z9][tree]_$(basename "${file// /_}").html; done
but the same problem with the colorization (only in cron) holds.
The text of the full script:
#!/bin/bash
List_make_R_general=/track/to/location_1.txt
List_R_gen_general=/track/to/location_2.txt
cron_log=/track/to/location_3.txt
echo > $cron_log
cat "$List_make_R_general" | while read file; do find "$file" -type d; done | tee "$List_R_gen_general"
cat "$List_R_gen_general" | while read file; do tree -axC "$file" | aha --title $(basename "${file// /_}") > "$file"/[z9][tree]_$(basename "${file// /_}").html; done
cat "$List_R_gen_general" | while read file; do tree -axC "$file" -I "*.JPG" | aha --title $(basename "${file// /_}") > "$file"/[z9][tree]_$(basename "${file// /_}")_[excl].html; done
echo -e "Tree done successfully: $(date) \n" >> $cron_log
exit
I worked at a similar problem with
htop
lately, you need to setTERM=xterm
in your script:Instead of using
export
you can also set the variable for everytree
invocation directly:The
TERM
variable tellstree
which type of terminal you are using. What probably1 matters in this case is the text window’s capability of displaying color:xterm
is built with 8 colors while e.g.xterm-256color
– you guessed it – is built with 256 colors. You can get a list of possible values for your system withls -1 /lib/terminfo/x
and view and compare their capabilities withinfocmp
, e.g.1 As noted in the comments
tree
actually just tests forTERM
to be set to anything at all, soTERM=my_precious tree
works as well. Giving it a valid value seems a good idea though.Further reading:
man infocmp
andman 5 terminfo