add custom tail for 500 exceptions
[dotfiles] / .bash_function
1 #!/bin/sh
2 # my weird function file
3 # lots of this coming from the internets
4
5 my_tail_500(){
6 # test if given argument
7 if [ $# -ne 1 ]; then
8 # TODO: print usage?
9 local default="/var/log/nginx/access.log"
10 tail -f $default | awk '$9 == 500 { print $0 }'
11 else
12 local log=$1
13 tail -f $log | awk '$9 == 500 { print $0 }'
14 fi
15 }
16
17
18 # _ssh_agent() {
19 # command -v ssh-agent >/dev/null || return
20 # [ "$SSH_CONNECTION" ] && return
21 # local info=$HOME/.cache/ssh-agent-info
22 # [ -f $info ] && . $info >/dev/null
23 # [ "$SSH_AGENT_PID" ] && kill -0 $SSH_AGENT_PID 2>/dev/null || {
24 # mkdir -p $(dirname $info)
25 # ssh-agent >$info
26 # . $info >/dev/null
27 # }
28 # } _ssh_agent
29
30
31 _ssh_add() {
32 local key=$1
33
34 [ "$SSH_CONNECTION" ] && return
35 ssh-add -l | grep $key >/dev/null || ssh-add $key
36 }
37
38 ssh() {
39 local remote=$1
40
41 case $remote in
42 "vm1") _ssh_add $HOME/.ssh/id_rsa_kratos ;;
43 "phobos") _ssh_add $HOME/.ssh/id_rsa_phobos ;;
44 *) #echo "valid key not found" && exit 1 ;;
45 esac
46 command ssh "$@"
47 }
48
49 # scp() {
50 # local file=$1
51 # local remote=$2
52
53 # case $remote in
54 # "vm1:") _ssh_add $HOME/.ssh/id_rsa_kratos ;;
55 # "phobos:") _ssh_add $HOME/.ssh/id_rsa_phobos ;;
56 # esac
57
58 # command scp "$@"
59 # }
60
61
62 # git() {
63 # case $1 in
64 # push|pull|fetch) _ssh_add ;;
65 # esac
66 # command git "$@"
67 # }
68
69 my_reboot_br0(){
70 sudo ifdown br0
71 my_up
72 }
73
74 my_up(){
75 ifup br0 &&
76 echo "nameserver 80.67.169.12" | sudo tee /etc/resolv.conf
77 }
78
79 my_weather(){
80 local town=$1
81 curl -4 "http://wttr.in/"$town
82 }
83
84 my_dotargz(){
85 local tarfile=$1
86 local foldertobezipped=$2
87 tar -zcvf $1 $2
88 #tar -cvf - file1 file2 dir3 | gzip > archive.tar.gz
89 }
90
91 my_dotarbz2(){
92 local tarfile=$1
93 local foldertobezipped=$2
94 tar -jcvf $1 $2
95
96 }
97
98 # zip some files using python
99 my_zipit(){
100 local zipfile=$2
101 local tobezipped=$1
102 # call the zip module from python3
103 python3 -m zipfile -c $2 $1
104 }
105
106 # to unban an ip blocked because of fail ssh connection
107 my_fail2ban_unban_ip(){
108 local ip=$1
109 sudo fail2ban-client set ssh unbanip $ip
110
111 }
112
113 my_bak() { cp "$1" "$1_`date +%Y-%m-%d_%H-%M-%S`" ; }
114
115 my_whois_onport(){
116 # return the service on port
117 local port=$1
118 sudo lsof -i :$port
119 }
120
121 my_mount_set_of_partition(){
122 # Mount set of partitions for recovery.
123 for i in {1..12}; do
124 mkdir /media/sdd$i && mount -o ro /{dev,media}/sdd$i || rmdir /media/sdd$i ;
125 done
126 }
127
128 my_copy_file_to_clipboard() {
129 local filecontent=$1
130 [ -f $file ] && xclip -sel clip < $filecontent
131 }
132
133 my_usage() {
134
135 cat <<-EOF
136 usage: $PROGNAME options
137
138 Program deletes files from filesystems to release space.
139 It gets config file that define fileystem paths to work on, and whitelist rules to
140 keep certain files.
141
142 OPTIONS:
143 -c --config configuration file containing the rules. use --help-config to see the syntax.
144 -n --pretend do not really delete, just how what you are going to do.
145 -t --test run unit test to check the program
146 -v --verbose Verbose. You can specify more then one -v to have more verbose
147 -x --debug debug
148 -h --help show this help
149 --help-config configuration help
150
151
152 Examples:
153 Run all tests:
154 $PROGNAME --test all
155
156 Run specific test:
157 $PROGNAME --test test_string.sh
158
159 Run:
160 $PROGNAME --config /path/to/config/$PROGNAME.conf
161
162 Just show what you are going to do:
163 $PROGNAME -vn -c /path/to/config/$PROGNAME.conf
164
165 EOF
166 }
167
168 my_change_owner_of_files() {
169 local user=$1; shift
170 local group=$1; shift
171 local files=$@
172 local i
173
174 for i in $files
175 do
176 chown $user:$group $i
177 done
178 }
179
180
181 my_template_function() {
182 # local vars
183 local PROGNAME=$(basename $0)
184 local PROGDIR=$(readlink -m $(dirname $0))
185 local ARGS="$@"
186 local first_arg=$1
187
188 # readonly var
189 #readonly local second_arg=$2;
190
191 # if no args, print usage
192 is_empty_string $ARGS && my_usage
193
194
195 }
196
197 my_list_venv(){
198 ls $HOME"/envs"
199 }
200
201 my_goto_venv() {
202 local dir=$1
203 local env=$HOME"/envs/"$dir"/source/"
204 #if source dir not exists, create & cd
205 [ -d $env ] && cd $env || mkdircd -p $env
206 # activate virtualenv
207 source $HOME"/envs/"$dir"/bin/activate"
208 }
209
210 # Taken from http://aaroncrane.co.uk/2009/03/git_branch_prompt/
211 find_git_repo() {
212 local dir=.
213 until [ "$dir" -ef / ]; do
214 if [ -f "$dir/.git/HEAD" ]; then
215 GIT_REPO=`readlink -e $dir`/
216 return
217 fi
218 dir="../$dir"
219 done
220 GIT_REPO=''
221 return
222 }
223
224 find_git_branch() {
225 head=$(< "$1/.git/HEAD")
226 if [[ $head == ref:\ refs/heads/* ]]; then
227 GIT_BRANCH=${head#*/*/}
228 elif [[ $head != '' ]]; then
229 GIT_BRANCH='(detached)'
230 else
231 GIT_BRANCH='(unknown)'
232 fi
233 }
234
235 # Taken from https://github.com/jimeh/git-aware-prompt
236 find_git_dirty() {
237 local status=$(git status --porcelain 2> /dev/null)
238 if [[ "$status" != "" ]]; then
239 GIT_DIRTY='*'
240 else
241 GIT_DIRTY=''
242 fi
243 }
244
245 find_git_stash() {
246 if [ -e "$1/.git/refs/stash" ]; then
247 GIT_STASH='stash'
248 else
249 GIT_STASH=''
250 fi
251 }
252
253 cdls() { cd "$@" && clear && ls; }
254
255
256 cl(){
257 if [ -d "$1" ]; then
258 cd "$1"
259 clear
260 ls -lh
261 else
262 cd
263 clear
264 ls
265 fi
266 }
267
268
269 mkdircd(){
270 mkdir -p "$@" && eval cd "\"\$$#\"";
271 }
272
273 my_emacs_servers(){
274 local serverdir="${TMPDIR:-/tmp}/emacs${UID}"
275 local -a servers
276 for file in ${serverdir}/*; do
277 if [[ -S ${file} ]]; then
278 servers+=("${file##*/}")
279 fi
280 done
281
282 echo "${servers[@]}"
283 }
284
285 my_fib(){
286 x=${1:-1}
287 y=${2:-1}
288 echo $(($x + $y))
289 fib $y $(($x + $y))
290 }
291
292
293 my_recursiveFibo() {
294 local start=0;
295 n="$1";
296 inc="$2";
297 while ((n < $inc));
298 do
299 result=$((start+n));
300 start=$n;
301 n="$result";
302 printf '%s ' "$result";
303 done;
304 }
305
306 #recursivFibo 1 2048
307
308 my_err() {
309 echo "[$(date + '%Y-%m-%dT%H:%M:%S%z')]: $@ >&2"
310 }
311
312 my_test() {
313 echo 'test';
314 }
315
316 my_test2(){
317 if my_test; then
318 my_err "unable to my_test"
319 exit "${E_DID_NOTHING}"
320 fi
321 }
322
323 my_pretty_print_json() {
324 python -m json.tool
325 }
326
327 my_not_start_service_on_boot(){
328 # service to not start on boot
329 local service=$1;
330 update-rc.d $service disable;
331 }
332
333 my_install_new_font(){
334 #sudo fc-cache -v -f
335 fc-cache -v -f;
336 }
337
338 my_launch_eth0(){
339 # set eth0 iface up
340 sudo ip link set eth0 up;
341 # ask for an ip via dhcp
342 sudo dhclient eth0;
343 }
344
345 #function to show the current branch
346 my_show_current_branch(){
347 git rev-parse --abbrev-ref HEAD
348 }
349
350 my_pdf_nbpages(){
351 local filename=$1;
352
353 echo $(pdftk $filename dump_data \
354 | grep -i numberofpages \
355 | awk '{print $2}');
356 }
357
358 my_pdf_explosion() {
359 local filename=$1;
360 echo $(pdftk $filename burst);
361 }
362
363 my_pdfs_to_xml() {
364 for i in $(ls | grep .pdf$); do
365 pdftohtml -xml $i;
366 done;
367 }
368
369 # function to show one line of file
370 my_xline_of_file(){
371 local line_number=$1;
372 local filename=$2;
373 local p='p';
374
375 echo $(sed -n $line_number$p $filename);
376 }
377
378 # function to extract in one command
379 my_xtract() {
380 local filename=$1;
381
382 if is_file $filename ; then
383 case $filename in
384 *.tar.xz) tar xvfJ $filename ;;
385 *.xz) tar xf $filename ;;
386 *.tar.bz2) tar xvjf $filename ;;
387 *.tar.gz) tar xvzf $filename ;;
388 *.bz2) bunzip2 $filename ;;
389 *.rar) unrar x $filename ;;
390 *.gz) gunzip $filename ;;
391 *.tar) tar xvf $filename ;;
392 *.tbz2) tar xvjf $filename ;;
393 *.tgz) tar xvzf $filename ;;
394 *.zip) unzip $filename ;;
395 *.Z) uncompress $filename ;;
396 *.7z) 7z x $filename ;;
397 *) echo "'$filename' cannot be extracted via extract" ;;
398 esac
399 else
400 echo "'$filename' is not a valid file"
401 fi
402 }
403
404 # function to list the content of an archive
405 my_list_archive_content() {
406 local filename=$1;
407
408 if is_file $filename ; then
409 case $filename in
410 *.tar.xz) tar tvfJ $filename ;;
411 *.tar.bz2) tar tvjf $filename ;;
412 *.tar.gz) tar tzvf $filename ;;
413 *.bz2) bunzip2 $filename ;;
414 *.gz) gunzip -l $filename ;;
415 *.tar) tar tvf $filename ;;
416 *.tbz2) tar tvjf $filename ;;
417 *.tgz) tar tvzf $filename ;;
418 *.zip) unzip -l $filename ;;
419 *.Z) uncompress -l $filename ;;
420 *.7z) 7z l $filename ;;
421 *) echo "content of '$filename' cannot be listed :(" ;;
422 esac
423 else
424 echo "'$filename' is not a valid file"
425 fi
426 }
427
428 # dump a mysql database
429 my_dump_mysql_db() {
430 local database=$1;
431
432 echo "dumping database '$database' ..."
433 mysqldump -u patrick -ppatrick $database > $databse_dump_$(date +%m%d%Y).sql
434
435 }
436
437 my_dump_mysql_table() {
438 local database=$1;
439 local table=$2;
440
441 echo "dumping table '$table' from database '$database' ..."
442 mysqldump -u patrick -ppatrick $database $table > $table_dump_$(date +%m%d%Y).sql
443 }
444
445 my_uploadfile() {
446 local filename=$1
447 local ftp_url=$2;
448 local user=$3;
449 local password=$4;
450
451 echo "upload of '$filename' to '$ftp_url' by '$user' ..."
452 #curl -T $filename ftp://dev.africafilms.tv/movies/ --user dev.africafilms.tv:dev/aftv/DAK2602
453 curl -T $filename $ftp_url --user $user:$password
454 }
455
456 my_find_string() {
457 local string_to_find=$1;
458 local directory=$2;
459
460 echo "recursive looking for the string '$string' inside '$directory' directory"
461 grep -l -R -i -r $string_to_find $directory;
462 }
463
464 my_find_string2() {
465 local string_to_find=$1;
466 local directory=$2;
467
468 echo "recursive looking for the string '$string' inside '$directory' directory"
469 find $directory | xargs grep $string -sl;
470
471 }
472 # extract md5 hash from a string
473 my_xmd5() {
474 local string=$1;
475
476 echo "md5 hash of '$string' is: "
477 echo -n "$string" | md5sum;
478 }
479
480 # Creates an archive (*.tar.gz) from given directory.
481 my_maketar() {
482 local directory=$1;
483
484 tar cvzf "${directory%%/}.tar.gz" "${directory%%/}/";
485 }
486
487 # Create a ZIP archive of a file or folder.
488 my_makezip() {
489 local file=$1;
490
491 zip -r "${file%%/}.zip" "$file";
492 }
493
494 # Make your directories and files access rights sane.
495 my_sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;}
496
497 # Get IP adress on ethernet.
498 my_ip() {
499 local my_ip=$( /sbin/ifconfig eth0 \
500 | awk '/inet/ { print $2 } ' \
501 | sed -e s/addr://);
502 local my_gtw="gtw: "$(netstat -nr | awk '{print $2}' | sed -n 3p);
503 echo ${my_ip:-"Not connected"}
504 echo ${my_gtw:-"Not connected"}
505 }
506
507 # Get current host related info.
508 my_host_info() {
509 echo -e "\nYou are logged on ${BRed}$HOST"
510 echo -e "\n${BRed}Local IP Address :$NC" ; my_ip
511 echo -e "\n${BRed}Current date :$NC " ; date; calendar | head -1
512 echo -e "\n${BRed}Additionnal information:$NC " ; uname -a
513 echo -e "\n${BRed}Users logged on:$NC " ; \
514 w -hs \
515 | cut -d " " -f1 \
516 | sort \
517 | uniq
518 echo -e "\n${BRed}Machine stats :$NC " ; uptime
519 echo -e "\n${BRed}Memory stats :$NC " ; free -h
520 echo -e "\n${BRed}Diskspace :$NC " ; mydf / $HOME
521 echo -e "\n${BRed}Open connections :$NC "; netstat -pan --inet;
522 echo
523 }
524
525 # Pretty-print of 'df' output. Inspired by 'dfc' utility.
526 my_df() {
527 local fs=$1;
528
529 for fs ; do
530
531 if [ ! -d $fs ]
532 then
533 echo -e $fs" :No such file or directory" ; continue
534 fi
535
536 local info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )
537 local free=( $(command df -Pkh $fs | awk 'END{ print $4 }') )
538 local nbstars=$(( 20 * ${info[1]} / ${info[0]} ))
539 local out="["
540 for ((j=0;j<20;j++)); do
541 if [ ${j} -lt ${nbstars} ]; then
542 out=$out"*"
543 else
544 out=$out"-"
545 fi
546 done
547 out=${info[2]}" "$out"] ("$free" free on "$fs")"
548 echo -e $out
549 done
550 }
551
552 # create_vm(){
553 # debootstrap --verbose \
554 # --variant=minbase \
555 # --arch=i386 --include ifupdown,locales,libui-dialog-perl,dialog,dhcp3-client,netbase,net-tools,iproute,openssh-server \
556 # sid /var/lib/lxc/sid http://ftp.debian.org/debian
557
558 # }
559
560
561 my_add_todo(){
562 local rememberfile="$HOME/.remember"
563 # if the file not exists, touch it
564 [[ ! -f $rememberfile ]] && touch $rememberfile
565 if [ $# -eq 0 ] ; then
566 echo "Type what you want to remember then, hit ^D: "
567 cat - >> $rememberfile;
568 else
569 #echo $(date +%m%d%Y)" -- $@" >> $rememberfile
570 echo $(date +%F)" -- $@" >> $rememberfile
571 fi
572 }
573
574 my_reminder(){
575 local rememberfile="$HOME/.remember"
576
577 #is_not_file $remberfile && echo 'nothing to do' ||
578 #is_empty $rememberfile && echo 'nothing to do' ||
579 #display_todo "$@"
580 is_not_file $rememberfile || [[ $(cat $rememberfile | wc -l) = 0 ]] && echo "nothing to do" || my_display_todo "$@";
581 }
582
583 my_display_todo(){
584
585 local rememberfile="$HOME/.remember"
586 echo $#;
587 #[[ $# -eq 0 ]] && more $rememberfile || grep -i "$@" $rememberfile | more;
588 [[ $# -eq 0 ]] && is_file $rememberfile && is_not_empty_file $rememberfile && cat $rememberfile || grep -i "$@" $rememberfile;
589 }
590
591
592 my_lsbytesum() {
593 #lsbytesum - sum the number of bytes in a directory listing
594 TotalBytes=0
595 for Bytes in $(ls -l | grep "^-" | awk '{ print $5 }')
596 do
597 let TotalBytes=$TotalBytes+$Bytes
598 done
599 TotalMeg=$(echo -e "scale=3 \n$TotalBytes/1048576 \nquit" | bc)
600 echo -n "$TotalMeg"
601 }
602
603 # list
604 my_create_list(){
605 local listname=$1;
606 declare -a $listname;
607 }
608
609 # sensonet
610
611 sensonet_create_event() {
612 curl -i -X "POST" -k -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" -d "name=$1" http://projects.emerginov.orange.sn/sensonet/resources/events/"$2"
613 }
614
615 sensonet_update_event() {
616 curl -i -X "PUT" -k -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" -d "name=$1" http://projects.emerginov.orange.sn/sensonet/resources/events/"$2"
617 }
618
619 sensonet_events() {
620 [[ $# -eq 0 ]] && curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/events/ || \
621 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/events/"$1"
622 }
623
624 sensonet_del_event() {
625 curl -i -X "DELETE" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/events/"$1"
626 }
627
628 sensonet_create_sensor() {
629 curl -i -X "POST" -k -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" -d "description=$1" http://projects.emerginov.orange.sn/sensonet/resources/sensors/"$2"
630 }
631
632 sensonet_update_sensor() {
633 curl -i -X "PUT" -k -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" -d "description=$1" http://projects.emerginov.orange.sn/sensonet/resources/sensors/"$2"
634 }
635
636 sensonet_del_sensor() {
637 curl -i -X "DELETE" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/sensors/"$1"
638 }
639
640 sensonet_sensors() {
641 [[ $# -eq 0 ]] && curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/sensors/ || \
642 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/sensors/"$1"
643 }
644
645 sensonet_create_network(){
646 curl -i -X "POST" -k -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=$1" http://projects.emerginov.orange.sn/sensonet/resources/networks/"$2"
647 }
648
649 sensonet_update_network(){
650 curl -i -X "PUT" -k -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=$1" http://projects.emerginov.orange.sn/sensonet/resources/networks/"$2"
651 }
652
653 sensonet_del_network(){
654 curl -i -X "DELETE" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/networks/"$1"
655 }
656
657 sensonet_networks(){
658 [[ $# -eq 0 ]] && curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/networks/ || \
659 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/networks/"$1"
660 }
661
662 sensonet_network_probes() {
663 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/networks/"$1"/probes
664 }
665
666 sensonet_create_probe() {
667 curl -i -X "POST" -k -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" \
668 -d "name=${1}&latitude=0.0&longitude=0.0&monitorMe=1&sleepingTime=0&networkId=univlab" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${2}"
669 }
670
671 sensonet_update_probe() {
672 curl -i -X "PUT" -k -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" \
673 -d "name=${1}&latitude=48.0&longitude=-1.0&monitorMe=1&sleepingTime=0" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${2}"
674 }
675
676 sensonet_probes() {
677 [[ $# -eq 0 ]] && curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/ || \
678 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"
679 }
680
681 sensonet_del_probe() {
682 curl -i -X "DELETE" -k -H -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${2}"
683 }
684
685 sensonet_probe_neighborhood(){
686 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"/neighborhood
687 }
688
689 sensonet_probe_set_sleeping_time(){
690 curl -i -X "POST" -k -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "duration=${2}" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"/sleepingtime
691 }
692
693 sensonet_probe_sensors(){
694 [[ $# -eq 1 ]] && curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"/sensors || \
695 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"/sensors/"${2}"
696 }
697
698 sensonet_probe_sensor_values(){
699 curl -i -X "GET" -k -H "Accept: application/json" http://projects.emerginov.orange.sn/sensonet/resources/probes/%2B221"${1}"/sensors/"${2}"/values
700 }
701
702 # from nixcraft
703 # Show top 10 history command on screen
704 function ht {
705 history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
706 }
707
708 # Wrapper for host and ping command
709 # Accept http:// or https:// or ftps:// names for domain and hostnames
710 _getdomainnameonly(){
711 local h="$1"
712 local f="${h,,}"
713 # remove protocol part of hostname
714 f="${f#http://}"
715 f="${f#https://}"
716 f="${f#ftp://}"
717 f="${f#scp://}"
718 f="${f#scp://}"
719 f="${f#sftp://}"
720 # remove username and/or username:password part of hostname
721 f="${f#*:*@}"
722 f="${f#*@}"
723 # remove all /foo/xyz.html*
724 f=${f%%/*}
725 # show domain name only
726 echo "$f"
727 }
728
729
730 ping(){
731 local array=( $@ ) # get all args in an array
732 local len=${#array[@]} # find the length of an array
733 local host=${array[$len-1]} # get the last arg
734 local args=${array[@]:0:$len-1} # get all args before the last arg in $@ in an array
735 local _ping="/bin/ping"
736 local c=$(_getdomainnameonly "$host")
737 [ "$t" != "$c" ] && echo "Sending ICMP ECHO_REQUEST to \"$c\"..."
738 # pass args and host
739 $_ping $args $c
740 }
741
742 host(){
743 local array=( $@ )
744 local len=${#array[@]}
745 local host=${array[$len-1]}
746 local args=${array[@]:0:$len-1}
747 local _host="/usr/bin/host"
748 local c=$(_getdomainnameonly "$host")
749 [ "$t" != "$c" ] && echo "Performing DNS lookups for \"$c\"..."
750 $_host $args $c
751 }