Solved Help to run a simple script on startup

How can run this script on startup?
Code:
#!/bin/bash   
sudo kldload fuse
sudo ntfs-3g /dev/ada2s1 /mnt/ -o -ro
xdg-open /mnt/ &> /dev/null
 
The best way to load kernel module is /boot/loader.conf
Code:
fuse_load="YES"

The ntfs-3g() can be mounted via /etc/fstab
Manual page has the example for fstab.
Another example for ntfs-3g here: https://forums.freebsd.org/threads/using-freebsd-as-desktop-os.57329/page-2#post-339118


But you can use crontab for your script.
Read the manual page crontab(5)
Code:
@reboot         Run once, at startup of cron.

Another way is: /etc/rc.local - rc.local()

In other case - try to write your own /usr/local/etc/rc.d/ script.
 
The best way to load kernel module is /boot/loader.conf
Actually, this is the 'old' way of doing it. Only put drivers in loader.conf that are essential for the system to boot. Everything else can be added to kld_list in rc.conf:
Code:
kld_list="fuse"

Code:
#!/bin/bash
/bin/bash doesn't exist on FreeBSD. And don't use bash for such a simple script in any case.

Code:
sudo ntfs-3g /dev/ada2s1 /mnt/ -o -ro
Don't use /mnt for (semi)permanent mounts, it's for temporary mounts. And just add this to /etc/fstab:
Code:
/dev/ada2s1     /somedir/ntfs/     ntfs   mountprog=/usr/local/bin/ntfs-3g,late,ro    0   0
 
Perfect, So ... How do I run the script or something else when the system starts? (I need to run a script at startup.)
 
As im already noted, /etc/rc.local still works. It's a rather old way to run things at boot but it still works.
 
Also methinks everything in /usr/local/etc/rc.d/* which has "sh" extension is executed.
In addition, you better use full path in scripts unless you set up the environment for your script. In your case sudo and other commands are unlikely to be found.
 
Simple example crontab: (I'm not sure it's that simple)

# use /bin/sh to run commands, overriding the default set by cron
SHELL=/bin/sh
@reboot /home/username/script.sh
 
I need to execute a command with sudo at the startup in the script
Also methinks everything in /usr/local/etc/rc.d/* which has "sh" extension is executed.
In addition, you better use full path in scripts unless you set up the environment for your script. In your case sudo and other commands are unlikely to be found.
 
Simple example crontab:
@reboot /home/username/script.sh
In case of using system crontab /etc/crontab
Try to add the line like this:
Code:
@reboot root /home/username/script.sh

In case of using user's crontab ( root has user's crontab too ):
Run these commands. Root's crontab will be opened with ee() editor.
setenv EDITOR ee
crontab -u root -e

By then add the line like this:
Code:
@reboot /home/username/script.sh
 
In case of using system crontab /etc/crontab
Try to add the line like this:
Code:
@reboot root /home/username/script.sh

In case of using user's crontab ( root has user's crontab too ):
Run these commands. Root's crontab will be opened with ee() editor.
setenv EDITOR ee
crontab -u root -e

By then add the line like this:
Code:
@reboot /home/username/script.sh
Thank you! Its working!
 
Back
Top