Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: 1 ... 8 9 [10]

Author Topic: Ronski's Pfsense router build  (Read 35249 times)

Ronski

  • Helpful
  • Kitizen
  • *
  • Posts: 3921
Re: Ronski's Pfsense router build
« Reply #135 on: December 01, 2020, 10:19:43 AM »

Thank you very much for doing that, when I get chance I'll give it go.
Logged
Formerly restrained by ECI and ali,  now surfing along at 390/36  ;D

Ronski

  • Helpful
  • Kitizen
  • *
  • Posts: 3921
Re: Ronski's Pfsense router build
« Reply #136 on: January 10, 2021, 11:22:06 AM »

I had completely forgotten about this until this morning.

I done a quick bash script, you can try in shell, not sure if it will work on the default shell that is included with pfsense, 'pkg install bash', should get you bash though.  If you want to the default shell change the first line from bash to sh

Code: [Select]
#!/usr/bin/env bash

wanif=pppoe0
previousip=`cat /tmp/currentip`
ip=`ifconfig $wanif | grep -w inet | awk '{print $2}'`

echo $ip > /tmp/currentip

if [[ "$ip" == "$previousip" ]]; then
exit 0
else
echo "ip has changed from $previousip to $ip"  | /usr/local/bin/mail.php -s"IP changed on pfSense"
fi

run ifconfig first to see which interface has the wan ipv4, set the wanif line to that interface, you then will need to either run the script first to populate the /tmp/currentip file or manually populate it yourself.

I however see no shell command that can be used to send emails hence the commented line, so may need to install a package for that or find a way to use the pfsense mailer system from the cli.

--edit--

I found a way that works, from this post here, so edited the script in post.  This method is nice as it uses the pfSense mailer settings, so wont send e.g. if you disable the mailer in the pfSense GUI.

https://forum.netgate.com/topic/103886/solved-sending-mail-with-pfsense/4

I'm struggling with this, and not really getting anywhere with Googling.

I've installed Bash
I've worked out that em2 is the interface
I've installed Cron

and this is now where I'm struggling, it would appear that cron just runs a command to run the script, rather than entering the script directly into cron.

How do I create the script, and where do I save it?
Once I've done that what command do I enter into cron to run the script?
How do I access the resultant file?

This is really basic stuff in Windows, but it might as well be in Chinese  :wall:
Logged
Formerly restrained by ECI and ali,  now surfing along at 390/36  ;D

broadstairs

  • Kitizen
  • ****
  • Posts: 3414
Re: Ronski's Pfsense router build
« Reply #137 on: January 10, 2021, 11:38:09 AM »

I assume this is Linux or similar, so this article https://www.linux-magazine.com/Issues/2019/225/Command-Line-at-cron-anacron may help. I'm lazy these days and use a GUI Linux system to run cron jobs  ;)

Stuart
Logged
ISP:TalkTalk Connection:FTTC Cab:ECI Router:Netgear D6220

Ronski

  • Helpful
  • Kitizen
  • *
  • Posts: 3921
Re: Ronski's Pfsense router build
« Reply #138 on: January 10, 2021, 11:55:29 AM »

Thanks Stuart, yes it's Linux  :( and unfortunately that doesn't help, that seems to focus more on the actual scheduling, which I have worked out. Its creating the script, where to save it, and the commands required to run it from the cron schedule that has me stumped.

Logged
Formerly restrained by ECI and ali,  now surfing along at 390/36  ;D

broadstairs

  • Kitizen
  • ****
  • Posts: 3414
Re: Ronski's Pfsense router build
« Reply #139 on: January 10, 2021, 12:24:19 PM »

Well initially you can store it anywhere, cron jobs can be run as a user or as root if they need system wide access. I would create it in Linux to eliminate possible issues with line endings. Yes cron executes the schedules the script rather than running it so that's why permissions are important.

Stuart
Logged
ISP:TalkTalk Connection:FTTC Cab:ECI Router:Netgear D6220

Chrysalis

  • Content Team
  • Addicted Kitizen
  • *
  • Posts: 6354
Re: Ronski's Pfsense router build
« Reply #140 on: January 16, 2021, 01:55:19 PM »

install nano if it isnt there (text editor), 'pkg install nano'.

or you can create in windows (make sure unix format for file), and then upload it.

To setup the cron there is a cron package inside the package manager, after that is installed, can add to that.

example line for cron for hourly. (although the ui cron package I think makes this easier).  Assuming script is called ipcheck.sh and is located in /root path.

0 * * * * root /root/ipcheck.sh

That line would be pasted in /etc/crontab

However the way I suggest is install the cron package, and then in "services -> cron" menu it is accessible.

in the ui set minute to anything from 0-59 (the time past the hour to run) and in the hour, day, day of week, day of month boxes put * in each one. user as root, and path to script in bottom box.

Also 'chmod 700 /root/ipcheck.sh' to make script executable. That should be fine if it is owned as root, chmod 755 will also work although less secure, but given pfsense is usually not a multiuser system it probably isnt a concern.
« Last Edit: January 16, 2021, 02:05:09 PM by Chrysalis »
Logged
AAISP - Billion 8800NL bridge & PFSense BOX running PFSense 2.4 - ECI Cab - LINE STATISTICS CLICK HERE

Ronski

  • Helpful
  • Kitizen
  • *
  • Posts: 3921
Re: Ronski's Pfsense router build
« Reply #141 on: January 16, 2021, 03:49:39 PM »

Thanks Chrysalis, that was so easy, knew it would be just couldn't think how to do it, thank you.

Running the script manually from within pfSense (Diagnostics / Command Prompt) it works perfectly, I've manually edited ipcheck.sh to the wrong IP address and I'll see if it works at 16:00

Thank you again.
Logged
Formerly restrained by ECI and ali,  now surfing along at 390/36  ;D

Ronski

  • Helpful
  • Kitizen
  • *
  • Posts: 3921
Re: Ronski's Pfsense router build
« Reply #142 on: January 16, 2021, 05:10:32 PM »

It didn't work at 16:00, but I think I incorrectly put 'chmod 700 /root/ipcheck.sh' as the command, once changed to '/root/ipcheck.sh' it works fine.

I've no real idea what chmod 700 does, from googling seems to be some sort of file protection options, but I did enter "chmod 700 /root/ipcheck.sh" from Diagnostics / Command Prompt page within pfSense so perhaps that did something first, then when that didn't appear to do anything I'd tried just  /root/ipcheck.sh

Anyway all seems to be working now.
Logged
Formerly restrained by ECI and ali,  now surfing along at 390/36  ;D

Chrysalis

  • Content Team
  • Addicted Kitizen
  • *
  • Posts: 6354
Re: Ronski's Pfsense router build
« Reply #143 on: January 16, 2021, 05:49:54 PM »

glad its working :)

unix permission system applies permissions based on the total sum of the digit.

1 execute
2 write
4 read

so 7 is everything, 6 would be read+write, 5 read+execute.
The first digit is for owner of file, second digit is for group owner of file, third digit is for all users (global).
Logged
AAISP - Billion 8800NL bridge & PFSense BOX running PFSense 2.4 - ECI Cab - LINE STATISTICS CLICK HERE
Pages: 1 ... 8 9 [10]