在网格portal中,有时候需要web服务器中实现身份切换,这个脚本的内容可以实现:

> cat test.sh
#!/usr/bin/expect -f
spawn -noecho su [lindex $argv 0] -c [lindex $argv 2]
set password [lindex $argv 1]
expect "*assword:"
send "$password\r"
expect eof
exit 

调用脚本,以用户user的身份执行命令

./test.sh user user's-password "ls -ivh /home/user"

这样就可以在web程序中实现身份切换来执行相应权限的操作,比如文件管理

相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-07-17
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-12-07
相关资源
相似解决方案