简体   繁体   English

在Linux内核中执行bash脚本

[英]Execute bash script in linux kernel

I have read many so questions and answers about this topic but I still don't have any idea why my program doesn't work. 我已经阅读了很多有关该主题的问题和答案,但是我仍然不知道为什么我的程序无法正常工作。

My script: 我的剧本:

ac AC

   #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 /home/tomasz/s.sh

#for example
reboot
# but in the future here will be sending file by ftp

What am I doing wrong? 我究竟做错了什么? Why doesn't script run? 为什么脚本不运行?

使用/bin/bash作为可执行文件,并使用脚本作为第一个参数:

char* argv[] = {"/bin/bash", "/home/tomasz/s.sh", NULL};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM