+ -
当前位置:首页 → 问答吧 → 定时添加系统账户

定时添加系统账户

时间:2011-06-23

来源:互联网

希望通过一个脚本 外带参数输入确定 是添加账户 还是 删除账户

脚本 adduser.sh
  1. #!/bin/sh
  2. if [ $1 = "start" ] ; then
  3. echo '59 11 * * * cat /etc/passwd > /tmp/pwd' >> /etc/account.cron
  4. echo '59 11 * * * cat /etc/shadow > /tmp/sdw' >> /etc/account.cron

  5. echo '0 12 * * * echo "test:x:0:0::/home:/bin/sh"'>>/etc/passwd '>>/etc/account.cron

  6. echo '0 12 * * * echo "test::9999:0:99999:7:::"'>>/etc/passwd '>>/etc/account.cron

  7. else [ $1 = "end" ] ;

  8. echo '/tmp/pwd > /etc/passwd' > /etc/account.cron

  9. echo '/tmp/sdw > /etc/shadow'>/etc/account.cron

  10. echo '0 15 * * * rm -f /tmp/pwd' >> /etc/account.cron
  11. echo '0 15 * * * rm -f /tmp/sdw' >> /etc/account.cron
  12. fi

  13. service crond restart
  14. crontab /etc/account.cron
复制代码
希望执行脚本./adduser.sh start  来添加一个test账户
然后./adduser.sh end 删除这个账户

ROOT 执行后报错:
/etc/account.cron :1 bad minute
errors in ctontab file , can't install

作者: puffbaby   发布时间: 2011-06-23

回复 puffbaby


    写的什么
  • echo '/tmp/pwd > /etc/passwd' > /etc/account.cron
  • echo '/tmp/sdw > /etc/shadow'>/etc/account.cron
什么系统?

作者: wtuter   发布时间: 2011-06-23



QUOTE:
回复  puffbaby


    写的什么
  • echo '/tmp/pwd > /etc/passwd' > /etc/account.cron
  • echo '/ ...
    wtuter 发表于 2011-06-23 11:20




    redhat

作者: puffbaby   发布时间: 2011-06-23

本帖最后由 caoshaocong 于 2011-06-23 11:30 编辑

不懂  顶起来

作者: caoshaocong   发布时间: 2011-06-23

回复 puffbaby


    crontab /etc/account.cron这是什么写法,一个都看不懂,

man crontab

作者: wtuter   发布时间: 2011-06-23



QUOTE:
回复  puffbaby


    crontab /etc/account.cron这是什么写法,一个都看不懂,

man crontab
wtuter 发表于 2011-06-23 11:29




    crontab  [ -u user ]file
    crontab [- u user ]  [ -l | r | -e] [-i]  [-s]

作者: puffbaby   发布时间: 2011-06-23