Created
September 13, 2021 16:37
-
-
Save zfhxi/7e37395936b2e3f60a755a801977cf01 to your computer and use it in GitHub Desktop.
Linux非root用户判断当前SSH会话是否为开机后的第一次连接
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| last_login_timestr=`last username | head -n 2 | awk 'NR==2' |awk '{print $5,$6,$7}'` | |
| last_login_timestamp=`date -d "$last_login_timestr" +%s` | |
| last_boot_timestr=`who -b | awk '{print $3,$4}'` | |
| last_boot_timestamp=`date -d "$last_boot_timestr" +%s` | |
| #echo "$last_login_timestamp" | |
| #echo "$last_boot_timestamp" | |
| diff=`expr $last_login_timestamp - $last_boot_timestamp` | |
| if [ $diff -lt 3 ];then | |
| echo 'first login!' | |
| # check syncthing | |
| syncthing_owner=`ps -o ruser=userForLongName -e -o cmd |grep username |grep syncthing |grep -v grep | awk '{print $1}'` | |
| if [ "$syncthing_owner" != "" ]; then | |
| echo "syncthing is running!" | |
| else | |
| echo "syncthing is not running!" | |
| nohup syncthing > /home/username/AppLogs/syncthing.log 2>&1 & | |
| echo "syncthing starts to run!" | |
| fi | |
| # check wandb local | |
| wandb_ports=`docker ps -a |grep 1636 |grep -v grep | awk '{print $10}'` | |
| if [ "$wandb_ports" != "" ]; then | |
| echo "wandb-local is running!" | |
| else | |
| echo "wandb-local is not running!" | |
| wandb local -p 1636 | |
| echo "wandb-local starts to run!" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment