在linux 系统的inittab系统服务器中运行程序需要设置环境变量



自己测试成功,记录一下, 因为这个好像不好现实.


参见 http://unix.stackexchange.com/questions/271963/in-inittab-trying-to-set-environment-variable-before-executing-script



Looking at the source code of the Linux sysvinit implementation, it does run a shell when it sees shell special characters, but it adds exec before the string, which makes it possible to put redirections and use special characters in arguments but not to set an environment variable in this way.

  } else if (strpbrk(proc, "~`!$^&*()=|\\{}[];\"'<>?")) {
  /* See if we need to fire off a shell for this command */
        /* Give command line to shell */
        args[1] = SHELL;
        args[2] = "-c";
        strcpy(buf, "exec ");
        strncat(buf, proc, sizeof(buf) - strlen(buf) - 1);
        args[3] = buf;
        args[4] = NULL;

A straightforward solution would be to run env.

scpt:234:once:env RSYNC_OPTIONS=-q /path/to/script/script.sh arg1 arg2 arg3 2>&1

Some possible workarounds to illustrate how to run an arbitrary command:

scpt:234:once:>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3 2>&1
scpt:234:once:2>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3

我使用这行:


null::respawn:2>&1; DISPLAY=:0.0 exec /bin/sysset


仅此记录.....



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值