Run shell script at startup (Kali Linux)

5,448

I'm not really familiar with Kali, but as I remember it does have systemd installed.

So, systemd is a good thing and I think it fits to your problem. Using it is easy and is a common thing used widely in practice.

Here you can read more about it. Basically you need to add a service config to your service scripts, which runs your script, and you're done. If you need an example, feel free to ask.

Share:
5,448

Related videos on Youtube

SinByCos
Author by

SinByCos

Updated on September 18, 2022

Comments

  • SinByCos
    SinByCos over 1 year

    This seems like a very basic thing to do, and I have even followed a few tutorials to get a simple script to be run at startup, but to no avail.

    Here is what my script, which is in the root directory, looks like:

    #! /bin/bash
    xmodmap ~/.xmodmaprc
    echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout
    

    The script basically changes my keymap, by switching control and command keys (as I'm on a macbook). It has been chmod'ed to be executable, so that it executes successfully when I do ./keymap_fix.sh or I do /root/keymap_fix.sh

    I have followed these simple tutorials https://www.cyberciti.biz/tips/linux-how-to-run-a-command-when-boots-up.html and https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

    So, I have copied the shell script to /etc/init.d and did this also update-rc.d keymap_fix.sh defaults 100

    I even tried setting up crontab in a similar way, by adding @reboot /root/keymap_fix.sh , but nothing works! Whenever I reboot, my keymap remains the same. :/

    Would be grateful if someone could help me out here, thanks!

    • davidgo
      davidgo over 6 years
    • SinByCos
      SinByCos over 6 years
      Tried that already, @davidgo
    • Dirk
      Dirk over 4 years
      I think you are misunderstanding the difference between "boot time" (system wide) and "login" (user specific) when using the term "startup". There is no point in running xmodmap at boot time (with SystemD or /etc/init.d), as it acts on the an X client (which is not running at that point in time). I think you want to add your commands in the shell init file (like .bashrc).
    • Dirk
      Dirk over 4 years
      Actually you describe two problems: You want to have the correct keymap on your PC. (This should be obtained by correctly configuring your system config files for the X client.) But you ask for help with a solution (start script automatically at "startup"), which in my opinion is sub-optimal for your initial problem.
  • Admin
    Admin almost 2 years
    Welcome to Super User. Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
  • Admin
    Admin almost 2 years
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
  • Admin
    Admin almost 2 years
    I guess I am bad at this then...