LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1162|回复: 3

[求助]如何开机自动运行自定义的脚本...?

[复制链接]
发表于 2007-12-29 23:30:35 | 显示全部楼层 |阅读模式
我是openSUSE 10.2的系统
google后有人说在/etc/init.d/boot.local里加入脚本就好

     一是我的/etc/init.d/里没有boot.local这个文件
     二是有人说/etc/init.d/boot.local 是 runlevel 之前跑的东西
我的目的是想在开机是检察history名令是服哦超过900条,超过的话就备份,然后将其删掉
     恳请各位告诉小弟该如何让此脚本在开机 或者 打开一个新shell时运行...
发表于 2007-12-30 05:35:03 | 显示全部楼层
such script is not suitable for running from init although it can be done in such way. Because most of the init script is running under either root or privileged users and you as an end user might not interested in looking there cmd history. Put it into your .bashrc or .profile should be better.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-30 22:34:31 | 显示全部楼层
Sorry,recend the message as downstairs...
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-30 22:36:22 | 显示全部楼层
thanks!
I just want to backup the history cmd to a file,so I added some lines in the /root/.bashrc as:
  1 export HISTTIMEFORMAT="%F %T: "
  2
  3 . ./history.sh

And the history.sh:
  1 #!/bin/bash
  2 line=$(history | wc -l)
  3 if [ $line -le 900 ];then #Here using "-le" just to have a test
  4     echo >>/home/backup/history/history3
  5     echo "                  $(date)" >> /home/backup/history/history3
  6     history >> /home/backup/history/history3
  7     #history -c
  8 fi  

But when I build a new bash,the /home/hackup/history/history3 only contains the date,no history cmd...
However,directly running the history.sh as . ./history.sh in the /root just get it...
Please tell me why.
Thank you.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表