ubuntu-18.04 设置开机启动脚本

ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用。
1、建立rc-local.service文件

sudo vi /etc/systemd/system/rc-local.service

2、将下列内容复制进rc-local.service文件

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

Linux 查看端口占用情况

Linux 查看端口占用情况可以使用 lsof 和 netstat 命令。
lsof
lsof(list open files)是一个列出当前系统打开文件的工具。

lsof 查看端口占用语法格式:

lsof -i:端口号
实例
查看服务器 8000 端口的占用情况:

lsof -i:8000

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nodejs 26993 root 10u IPv4 37999514 0t0 TCP *:8000 (LISTEN)
可以看到 8000 端口已经被轻 nodejs 服务占用。

Linux中循环执行shell命令的方法

Linux命令行,循环执行shell命令
死循环
命令格式

while true ;do <command>; done;

可以将 command 替换为任意命令。
下面以echo “hello”; sleep 1;为 command 展示最终效果

效果

wanghan@ubuntu:~$ while true ;do echo "hello"; sleep 1; done;
hello
hello
hello
hello
hello
^C
wanghan@ubuntu:~$

每隔一秒,打印一次hello,直到按下Ctrl+C才停止。

普通计数循环
循环10次

mycount=0; while (( $mycount < 10 )); do  <command>;((mycount=$mycount+1)); done;

可以将 command 替换为任意命令。
下面以 echo “mycount=$mycount”;为 command 展示最终效果
效果

wanghan@ubuntu:~$ mycount=0; while (( $mycount < 10 )); do echo "mycount=$mycount"; ((mycount=$mycount+1)); done;
mycount=0
mycount=1
mycount=2
mycount=3
mycount=4
mycount=5
mycount=6
mycount=7
mycount=8
mycount=9

mycount计数到10后停止循环。

  • 或者使用for循环:
    使用i来循环执行10次命令。
for i in {1..10}; do echo "Hello"; done

用for循环更简单一些,下面是for的几种不同的使用方式:

Linux shell 实现用for循环100次的方法

今天小编就为大家分享一篇Linux shell 实现用for循环100次的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧.
前言

循环不管在程序中还是脚本中都需要经常用到,在写shell脚本时,经常需要for进行100次循环。这里谈谈几种从1到100的循环方法。

四种方法

C语言风格

for ((i=1; i<=100; i++))
do
  echo $i
done

Python风格(in的使用)

for i in {1..100}
do
  echo $i
done

Seq的使用
注意代码中不是单引号。

for i `seq 1 100`
do
  echo $i
done