I have the following script collecting data about current logged users.
#!/bin/bash
# Collecting users login statistics
CURRENT_ALL_USERS="path_to_log_file"
ADMIN="path_to_admin_dir"
STATIONS="$ADMIN/stations_list"
ALL_USERS_IN_STATIONS=0
eval `keychain --eval ~/.ssh/id_rsa`
for STATION in `cat $STATIONS`; do
TEMP_VAR=`ssh user@$STATION who | cut -d " " -f1 | sort -u | wc -l`
USERS_IN_STATION=$TEMP_VAR
let ALL_USERS_IN_STATIONS="$ALL_USERS_IN_STATIONS+$USERS_IN_STATION"
done
echo $ALL_USERS_IN_STATIONS > $CURRENT_ALL_USERS
Run periodically with cronjob:
* * * * * /path_to_script/script.sh
When the server reboots the script can't ssh to remote stations and I need to manually run the script for the first time.
What can I do to make the script work after reboot without manually running it the first time?