linux开机自动执行.sh脚本

设置Linux系统开机自动运行脚本 本文介绍了在Linux系统中设置开机自动启动脚本的五种方法。首先,通过修改/etc/rc.d/rc.local文件,将脚本路径添加到文件末尾,确保脚本在系统启动后执行。其次,使用crontab的@reboot任务,在系统重启时自动运行脚本。第三种方法适用于systemd系统,通过创建并启用systemd服务来实现开机启动。第四种方法是在/etc/profile.d/目录下创建.sh文件,系统启动时会自动执行该目录下的脚本。 阅读详情

编写开机自动执行的脚本auto.sh

#!/bin/sh
#chkconfig: 2345 20 80
#description:Server reboot.Execute auto.sh

#client post port 80 redirect 9527
#sudo iptables -A PREROUTING -t nat -i eth0 -p tcp —dport 80 -j REDIRECT —to-port 9527

#auto.sh log
DIR=/home/linux-nice
echo "execute auto.sh" > $DIR/auto_log.txt

chkconfig命令

chkconfig命令检查、设置系统的各种服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务

等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
#!/bin/sh 告诉linux服务器这是一个.sh脚本
**2345**对应linux服务器的2345阶段能执行auto.sh脚本
20表示启动优先级序号 80表示关闭优先级序号(就这个不太懂 有哪位大佬能提供资料吗)
[root@VM_158_86_centos ~]# cd /etc/rc.d/init.d/ 进入该文件夹
[root@VM_158_86_centos init.d]# vi auto.sh 编写脚本
[root@VM_158_86_centos init.d]# vi auto.sh 
[root@VM_158_86_centos init.d]# chmod +x auto.sh 给脚本添加执行权限
[root@VM_158_86_centos init.d]# chkconfig --add auto.sh  添加脚本至开机自启
[root@VM_158_86_centos init.d]# chkconfig auto.sh on 开启
[root@VM_158_86_centos init.d]# sudo reboot 重启

验证

请事先创建好/home/linux-nice/auto_log.txt 文件
然后重启服务器 sudo reboot
auto_log.txt是否输出了”execute auto.sh”
这里写图片描述
结果打印出来了 说明开机自动执行了该脚本

prefect

补充:
有可能linux系统没有/etc/rc.d/init.d/ 文件夹 就在/etc/rc.local

sh /path/xxx.sh命令
linux系统设置开机启动的两种方法systemd及rc.local(手工写sh脚本,手工写service服务) ExecReload=/usr/local/nginx/sbin/nginx -s reload:当服务需要重新加载配置时(例如,当 systemctl reload nginx 被调用时),这个命令将被执行。ExecStop=/usr/local/nginx/sbin/nginx -s stop:当服务需要停止时(例如,当 systemctl stop nginx 被调用时),这个命令将被执行。ExecStart=/usr/local/nginx/sbin/nginx:这定义了服务启动时应该运行的命令。 阅读详情

相关推荐

Windows平台SOEM控制禾川伺服:从环境搭建到使能状态机全链路实战

EtherCAT作为一种基于以太网的实时工业通信协议,凭借其高同步精度和低通信抖动的特性,已成为多轴运动控制领域的核心解决方案。其核心原理在于主站与从站间通过周期性过程数据交换实现精准控制。在技术实现层面,开源主站库SOEM提供了跨平台的协议栈实现,为开发者带来了灵活性与可控性。对于需要在Windows非实时操作系统上进行快速原型验证或与上位机生态集成的场景,构建一个稳定、正确的EtherCAT控制链路具有重要工程价值。这涉及到网络适配器配置、实时线程调度、以及遵循CIA 402标准的驱动器状态机管理等多个

weixin_34199335的博客 331

Linux开机自启.sh脚本(简单粗暴)

1、创建脚本(1)#切换到你将要存脚本的目录(2)编写脚本autorun.sh以下为脚本内容:(该执行脚本的意思是在/home目录下创建一个input.txt文件夹,并写入当前日期和hostname)2、将该脚本添加到启动文件中在最后一行添加你写的脚本(从根目录开始写)3、赋予权限chmod +x /etc/你的rc.local文件地址 需加上文件名 例:(/etc/rc.d/rc.local)

黑桃A的博客 1万+

AD9361数字调制入门:从IQ调制原理到动手实现第一个ASK信号(Vivado工程详解)

本文详细介绍了如何使用AD9361射频收发器实现ASK数字调制,从IQ调制原理到Vivado工程实现。通过Verilog代码示例和FPGA架构设计,帮助开发者理解纯逻辑实现数字调制解调的关键技术,特别适合软件无线电(SDR)初学者入门实践。

weixin_29158047的博客 384

Linux 开机运行sh 脚本 三种方法

Linux 开机运行sh 脚本 三种方法

星哲最开心 1万+

手把手教你用NetToPLCsim搭建西门子S7-1200仿真环境(附避坑指南)

本文详细指导如何利用NetToPLCsim与PLCSIM搭建西门子S7-1200仿真环境,实现无硬件条件下的PLC程序测试与上位机通信开发。内容涵盖软件选型、环境部署、关键参数配置及通信测试,并重点提供了连接失败、数据读写错误等常见问题的深度避坑指南,帮助工程师高效构建可靠的虚拟调试工作流。

a3b4c5的博客 629

Python的WNTR库---基于供水网络

WNTR使用小结(一) 本人最近主要再做设施网络的内容,主要聚焦供水管网(water distribution network,WDN),在做实验中主要用的包为WNTR,下载连接: 链接: WNTR.最好安装最新版本 如果有做这方面研究的小伙伴们需要测试数据可以直接从WNTR实例数据中下载,其中提供了四种规模大小的管网,格式为.inp,可以搭配Epanet使用。如果需要更多示例数据可私信我! 以下内容全部为本人自己探索的小心得,希望能给你带来一点点帮助,如果不够详尽可以自行参阅官方文档:链接: 官方文档.

pushhy的博客 4947

linux开机自启动sh脚本

linux开机自启动sh脚本。

weixin_36873225的博客 4100

水下井口装置及钻杆建模

内容:海上油气资源开采的过程中,通常会由海上钻井平台下入钻杆连接到海底井口装置。OrcaFlex软件可进行各种海洋工程结构动态分析,通过各项数据的输入,能够很方便地进行水下井口装置及钻杆建模。直接使用软件New Line及new vessel功能,再设置模型的各项参数(几何属性、弯曲刚度、轴线刚度、扭转刚度、泊松比等)即可建成井口装置及钻杆模型。 设置管线的几何属性:主要包括管线的内外径、壁厚、...

s0302017的博客 1153

arm linux 自动开机执行sh脚本

提取

weixin_39345762的博客 935

基于 Datawhale 开源量化投资学习指南(10):基于 LightGBM 的量化选股

通过本篇文章,我们深入探索了如何运用 LightGBM 机器学习模型实现量化选股。首先,我们通过获取股票的历史数据,进行特征工程和标签制作,将选股问题转化为一个分类问题。接着,我们使用 LightGBM 训练模型,并在验证集和测试集中评估了模型的表现。该选股策略的核心在于结合机器学习算法,从历史数据中寻找能够捕捉股票短期涨跌的关键特征,从而为投资者提供辅助决策支持。虽然本文的模型取得了一定的效果,但这只是量化投资领域的一小部分。

不想宅的冷同学 1358

Opencv项目实战:09 物体尺寸测量

《Opencv项目实战:09 物体尺寸测量》本项目主要是运用了之前扫描文档的思想,以A4纸为背景,检测其中区域的物体长和宽。我的摄像头无法固定,所以是手持的,且由于我在寝室里面是真的没有找到合适的测量物体以及背景色(全是米色或原木色的)。所以效果有所欠缺,但经过ps修改的图片,检测的效果还是很不错的。

m0_62919535的博客 1万+

linux开机自动执行脚本、运行程序

linux开机自动执行脚本、运行程序、/etc/rc.d/init.d、/etc/init.d、shell、环境变量

小白 1万+

【cmd】Win10家庭版找不到 gpedit.msc (组策略)的解决方法

目录 一、创建cmd文件 二、以“管理员身份”运行“gpedit.cmd”文件 三、运行“gpedit.msc”命令查看组策略 一、创建cmd文件 (1)新建一个文件名为“gpedit.txt”的txt文本文档: (2)文本中写入以下内容: @echo off pushd "%~dp0" dir /b C:\Windows\servicing\Packages\Micros...

顾三殇 —— 博客空间(软件测试) 4万+

16 开机自动登录脚本_centos8开机启动脚本

方法一(每次登录都会运行)将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本 (账号登录一次就执行,不符合开机执行,不开机不执行)https://www.cnblogs.com/liuhaidon/archive/2019/09/19/11549997.html方法二:(此方法可以正常开机执行,且不会每次登录都执行,...

weixin_33272515的博客 1532

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

linux 如何开机自动运行sh脚本

linux 如何开机自动运行某sh脚本。比如开机自动运行 /test.sh 第二个问题,还有什么办法可以确定test.sh已经正确运行了 要开机 运行只需将它加入到 rc.local ,一般为/etc/rc.d/rc.local 在其中加入以下行:sh /path/to/test.sh使用linux全局变量$?可以确定是否执行,如 if [$? eq 0]     then    

kim的专栏 5569

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

【linux系统】ubuntu18.04开机时自动运行命令或脚本

找到启动应用程序 点击添加,将要运行的命令填入 这样开机就会自动执行此命令了,如果想要运行脚本,就自己先写一个.sh文件,给文件加上x权限后,在命令栏中填入该文件的绝对地址即可 ...

moX980的博客 983

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

手把手教你设置Linux开机自动运行.sh脚本文件

本文介绍了如何在星图GPU平台上自动化部署‘测试开机启动脚本’镜像,实现Linux系统开机自动执行Shell脚本的功能。该镜像适用于服务自启、数据采集、系统监控等典型运维场景,帮助用户免去手动运行脚本的重复操作,提升服务器管理效率。

weixin_42601134的博客 864

linux开发板开机自启动脚本,linux 添加开机自启动脚本

Linux设置服务开机自动启动的方式有好多种,这里介绍一下通过chkconfig命令添加脚本为开机自动启动的方法。1. 编写脚本autostart.sh(这里以开机启动redis服务为例),脚本内容如下:#!/bin/sh#chkconfig: 2345 80 90#description:开机自动启动的脚本程序# 开启redis服务 端口为6379/usr/local/service/redis...

weixin_42129797的博客 3991

ubuntu python脚本开机自启动

开机自启动 step:1 首先创建你的sh脚本:auto_start.sh 脚本里面写上启动.py文件的语句:gedit auto_start.sh, 进行编辑 ## 切换到python脚本路径中 cd /home/ ## 根据自身实际情况用Python2/3 python3 test.py step:2 修改脚本权限:chmod 777 auto_start.sh step...

Trista2hong的博客 2952

Linux 系统设置开机自启动脚本的方法

Linux 系统设置开机自启动脚本的方法

qq_56834784的博客 1550

Linux配置开机启动执行脚本

当Linux开机启动后,将执行我们自定义的脚本命令,即进入到/myauto/sh目录下,再执行START_ALL.sh脚本。(我们运行启动项目的命令写在了START_ALL.sh脚本中,其实可以将命令直接写到autostart.sh中的)在项目部署的阶段,我们一般会将项目部署到Linux系统运行。我们可以将运行启动我们项目的命令写到脚本sh文件中,比如:autostart.sh。若在autostart.sh中没有书写**# chkconfig:**的内容,执行上面的命令将会出错。

李白 2358

centos开机执行sh脚本

创建sh测试脚本 vi /home/test.sh添加如下内容#!/bin/bash touch /home/test.txt 设置为开机执行 vi /etc/rc.d/rc.local在最后添加如下内容/home/test.sh 添加执行权限 chmod +x /home/test.sh chmod +x /etc/rc.d/rc.local

nanjizhiyin的专栏 1541

centos7.6开机时候执行脚本

简单的一个shell脚本 [root@test173 ~]#cat /root/bb.sh #!/bin/bash touch /mnt/1.txt echo ‘aaaa’ > /mnt/2.txt 网上都说修改这个 /etc/rc.local就行,实际上修改 /etc/rc.local等于修改/etc/rc.d/rc.local这个文件 [root@test173 ~]# ls -l...

qq_39043100的博客 899

linux笔记本设置开机自动禁用触摸板

触摸板有时候太麻烦了,使用键盘手总会不经意的碰着它 写个sh脚本开机自动禁用触摸板八… 原理: 使用modprobe这个bash命令自动卸载触摸板模块psmouse /etc/profile.d/文件夹下的sh脚本会在linux开机时执行 在/etc/profile.d/文件夹下创建一个sh脚本文件: 文件名随意,后缀 .sh 内容: #!/bin/bash modprobe -r psmo...

ikun 的博客 728

Linux开机自动执行自定义脚本或命令

在用户登录之前自动执行在用户登录之后自动执行:下述方法,实际尝试发现,之后再输入用户名和密码后才会自动执行。当如果不需要输入用户名或密码时,不知是否会自动执行,需要后续再做尝试。

yangsong4353的博客 1625
上一篇: SSH公钥登录远程服务器
下一篇: 服务器-IP 子网掩码 网关 DNS 梳理
code222vip
博客等级 码龄12年 33粉丝 30原创
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址