linux - 在linux内核中执行bash脚本

标签 linux bash module kernel system-calls

我已经阅读了很多关于这个主题的问题和答案,但我仍然不知道为什么我的程序不起作用。

我的脚本:

交流

   #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/

相关文章:

react-native - 如何在 React Native 项目中集成多语言

python - 全局和本地导入

linux - SQLITE_IOEERR : in Meteor

linux - 为什么我的 Dockerfile CMD 不起作用?

linux - EXT2打开文件时检查ACL权限在哪里?

linux - 如何切断 BASH 脚本中的路径?

vue.js - 如何在一个模块内从另一个模块使用 getter 进行 Vuex 状态

linux - UNIX:如何使用循环结构从 2 个文件输出数据?

bash - 尝试在 BASH 中多次发送 cURL

git - 如何确定git中的最后一个 merge 分支?