Help with script writing?

Bizarro252

Dabbler
Joined
Jul 1, 2019
Messages
36
Hello!
Is there a resource/intro to writing scripts for FreeNAS?

I want to create something suuuuper basic, I want to have a script to copy the contents of a folder within a jail to a shared folder so I can pass the logs over easily over my network.
I tried mounting this folder but I cant create it while there are files in it, and removing the files to mount the folder caused issues...

So for example do the below, but not have to type it out every time I want to do it :)

cd /mnt/data_pool/iocage/jails/..../logs
cp * /mnt/data_pool/...shared folder

Thanks!
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Hello!
Is there a resource/intro to writing scripts for FreeNAS?
For what you intend to do there is nothing FreeNAS special, so any beginners tutorial for tcsh will do fine.
There are hundreds of tutorials online. Just do a search https://www.google.com/search?q=tcsh+beginner+tutorial

You could also search for tutorials for the bash, as there are probably more tutorials available as it is
wider used. The tcsh is command shell when you log into the console of FreeNAS. But for a script
you can use bash or tcsh, there is not a too big difference. (Just my personal opinion)
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
For scripts:
  • A purist would say use the Bourne shell.
  • A pragmatist would say use bash.
  • Many would say avoid csh or tcsh for the reasons given here.
 

blueether

Patron
Joined
Aug 6, 2018
Messages
259
I think I would go the mount route:
Code:
root@freenas[~]# ls /mnt/SATA_Z2/iocage/jails/heimdall/root/var/log
auth.log        cron.0.bz2      dmesg.today     maillog         maillog.2.bz2   php-fpm.log     sendmail.st     utx.lastlogin
caddy.log       debug.log       dmesg.yesterday maillog.0.bz2   messages        ppp.log         sendmail.st.0   utx.log
cron            devd.log        lpd-errs        maillog.1.bz2   mount.today     security        setuid.today    xferlog
root@freenas[~]# mount_nullfs /mnt/SATA_Z2/iocage/jails/heimdall/root/var/log /mnt/SATA_Z2/FreeNAS/temp
root@freenas[~]# ls /mnt/SATA_Z2/FreeNAS/temp
auth.log        cron.0.bz2      dmesg.today     maillog         maillog.2.bz2   php-fpm.log     sendmail.st     utx.lastlogin
caddy.log       debug.log       dmesg.yesterday maillog.0.bz2   messages        ppp.log         sendmail.st.0   utx.log
cron            devd.log        lpd-errs        maillog.1.bz2   mount.today     security        setuid.today    xferlog
root@freenas[~]# umount /mnt/SATA_Z2/FreeNAS/temp
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,975
A simple rsync command run as a cron task from the GUI should do what you want.
Code:
rsync -av --delete /source/path /destination/path
 

Bizarro252

Dabbler
Joined
Jul 1, 2019
Messages
36
Thanks everyone. Gives me plenty to get started playing around with options.
 
Top