Samba一键安装shell脚本

回复 收藏
执行时需要带一个目录参数,为你想共享的目录,可以不存在,不存在脚本会自动创建
  1. #!/bin/bash
  2. is_samba_installed=`rpm -qa|grep samba|wc -l`
  3. if [ $is_samba_installed != 0 ]
  4. then
  5.     echo "You had already installed Samba."
  6.     exit 0
  7. fi
  8. echo "It will install Samba."
  9. sleep 1
  10. cnfdir="/etc/samba/smb.conf"
  11. chkok(){
  12.     if [ $? != 0 ]
  13.     then
  14.         echo "Error, Please try again."
  15.         exit 1
  16.     fi
  17. }
  18. yum install -y samba
  19. chkok
  20. sed -i 's/MYGROUP/WORKGROUP/' $cnfdir
  21. sed -i 's/user/share/' $cnfdir
  22. sed -i '$a\[fish]' $cnfdir
  23. if [ -d $1 ]
  24. then
  25.     cd $1
  26.     echo "test" > test.txt
  27.     sed -i '$a\[fish]\n\tcomment = Share All\n\tpath = "'$1'"\n\tbrowseable = yes\n\tpublic = yes\n\twritable = no' $cnfdir
  28. else
  29.     mkdir $1
  30.     cd $1
  31.     echo "test" > test.txt
  32.     sed -i '$a\[fish]\n\tcomment = Share All\n\tpath = "'$1'"\n\tbrowseable = yes\n\tpublic = yes\n\twritable = no' $cnfdir
  33. fi
  34. /etc/init.d/smb start
  35. chkok
  36. echo "Please input [\\sambaIP\sharename] to access the share dir."
2016-04-08 21:34 举报
已邀请:
0

balich

赞同来自:

谢谢分享!
0

opensky

赞同来自:

感谢你的工作, 这样能提升效率

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: