我已经阅读了很多关于这个主题的问题和答案,但我仍然不知道为什么我的程序不起作用。
我的脚本:
交流
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
#include<linux/kmod.h>
static int __init hello_start(void)
{
printk(KERN_INFO "Loading rooted module...\n");
char* argv[] = {"/home/tomasz/", "s.sh", NULL};
static char* envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL };
call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "exit.\n");
}
module_init(hello_start);
module_exit(hello_end);
/home/tomasz/s.sh
#for example
reboot
# but in the future here will be sending file by ftp
我做错了什么?为什么脚本不运行?
最佳答案
使用 /bin/bash
作为可执行文件并将您的脚本作为第一个参数:
char* argv[] = {"/bin/bash", "/home/tomasz/s.sh", NULL};
关于linux - 在linux内核中执行bash脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53395324/