Autorun a file when i start linux!

Ramon00

New Member
Joined
Jul 29, 2021
Messages
22
Reaction score
0
Credits
202
Hi folks, i want to autorun a file when a start linux and save information in a .txt located in desktop. Can you guys help me?
With the most regards,

Miguel.
 


Put the program you want to execute in your .bash_profile. When you login, the .bash_profile gets executed and it will execute whatever you have it in.
 
In your home directly. Because it starts with a ".". You need to do a 'ls -a' to physically see it. -a = all.
 
In your home directly. Because it starts with a ".". You need to do a 'ls -a' to physically see it. -a = all.
Sry but in my /home/ directory only find .bash_history, .bash_logout and bashrc, /home/ is the correct directory?
 
If it doesn't exist, you can just create it.

touch ~/.bash_profile
or just use an editor to create it and add what you need to it.

vim ~/.bash_profile

Just ensure the filename itself starts with a "."

The correct directory is the user's home direct. If the username is bob. It's /home/bob/.bash_profile
 
If it doesn't exist, you can just create it.

touch ~/.bash_profile
or just use an editor to create it and add what you need to it.

vim ~/.bash_profile

Just ensure the filename itself starts with a "."

The correct directory is the user's home direct. If the username is bob. It's /home/bob/.bash_profile
Ok i already create the .bash_profile, but whe i try do for example:

#/bin/bash

echo "HELLO" > teste.txt

exit 0

It didn't save in teste.txt the word HELLO, and i already create teste.txt. So i think i'm doing something rong.
 
Your .bash_profile is not a "script" in the normal sense you would create bash scripts.

With that said.
  • You don't need the shabang at the top. (ie, the "#!/bin/bash" ) Remove it.
  • Your shabang is incorrect anyhow. You're missing the exclamation point. #!/bin/bash
  • You do not exit from a .bash_profile. (remove the "exit 0")
  • The .bash_profile should not be executable. ("chmod -x ~/.bash_profile")
  • To test execute the .bash_profile (without logging in / out) you would execute it by doing (without quotes) ". ~/.bash_profile" Notice the "." then a space " ", then the filename. "~/.bash_profile"
 
Your .bash_profile is not a "script" in the normal sense you would create bash scripts.

With that said.
  • You don't need the shabang at the top. (ie, the "#!/bin/bash" ) Remove it.
  • Your shabang is incorrect anyhow. You're missing the exclamation point. #!/bin/bash
  • You do not exit from a .bash_profile. (remove the "exit 0")
  • The .bash_profile should not be executable. ("chmod -x ~/.bash_profile")
  • To test execute the .bash_profile (without logging in / out) you would execute it by doing (without quotes) ". ~/.bash_profile" Notice the "." then a space " ", then the filename. "~/.bash_profile"
So i don´t know but it didn't worked so i did a research and i used ~/crontab -e and it works. Thank you so much to trying to help me!
 

Members online


Top