Bash script to reboot network devices via telnet

I noticed that some cheap managed network equipment can start working incorrectly in a few days or weeks, so I had an idea to write a reboot script and add it to the cron.

Content of the script:

#!/bin/bash
(
sleep 5
echo "admin"
sleep 5
echo "password"
sleep 5
echo "reboot"
sleep 5
echo "y"
sleep 5
echo "quit"
) | telnet 192.168.1.10

sleep 5 means a pause of 5 seconds after each command, this value is optimal for long thinking equipment. For example, for client switches D-Link DES-3200 pause can be completely removed or set 1.

See also:
Using and configuring CRON

Firmware Update Dahua IPC-HFW1320S-W

For the test, I will update the firmware on the IP camera Dahua IPC-HFW1320S-W.

Let’s see what firmware is installed, open the web interface of the device, select the “Setting” tab, on the left the “Information” – “Version” menu.

In my case, the Russian version of the firmware was installed:

System Version 2.400.0001.11.R, Build Date: 2017-04-01
WEB Version 3.2.1.392220
ONVIF Version 2.42

Let’s see a new firmware on the official site and download it
https://www.dahuasecurity.com/products/productDetail/5631

The firmware file is usually in the archive, so unpack it.

In the web interface of the device, open the “Setting” tab, on the left in the “System” menu – “Upgrade”.
Press the “Browse…” button, select the file of the new firmware unpacked from the archive and press the “Upgrade” button to start the update process, which will last about 5 minutes, at this time you can not turn off the power of the device.

I was flashing with the English firmware, after the firmware in the “Information” – “Version” menu, the following was displayed:

System Version 2.400.0000000.16.R, Build Date: 2017-08-31
WEB Version 3.2.1.490211
ONVIF Version 16.12(V2.3.1.458331)

How to remove hiberfil.sys file

The file hiberfil.sys is created and used by the operating system for the correct operation of the sleep mode. When the computer goes into sleep mode, all data from the RAM is stored in this file. The size of this file is usually not less than the amount of computer RAM (RAM).

If you need to delete the hiberfil.sys file, you will have to disable sleep and hibernation on your computer. To do this, open “Control Panel” -> “Power Supply” -> “Power Scheme Setup” and in the window that opens, click “Never” and click “OK” in the opposite window.
Next, you need to type the following command in the command line or “execute” (Windows + R):

powercfg -h off

or

powercfg –hibernate –off

and click “OK”. The hiberfil.sys file will be deleted automatically.
If you suddenly changed your mind and decided to return to hibernation, then you can run the command:

powercfg -h on

These manipulations must be performed on behalf of the administrator.

The solution of the error “Kernel failure” and “Out of memory” in Mikrotik

There was a problem, often began to reboot itself MikroTik CAS125-24G-1S-RM.
The firmware at that time was the last one – WebFig v6.9
The following information was displayed in the logs:

System rebooted because of kernel failure
Out of memory condition was detected
router was rebooted without proper shutdown

Having looked in “system” -> “resources” it was evident that the free memory of the device is constantly decreasing.
Then I began to recall what was involved and configured on the device.
Bumping into and looking “Cache Used” in “IP” -> “Web Proxy” it was evident that the size of the cache is constantly growing.
From here it was clear that when the device’s memory was running out and the kernel crashed.
Therefore, the solution to this problem was to restrict the proxy cache by specifying the maximum size in the “Max. Cache Size“.
Done.

Solution of the error “Please run this cronjob as user amavis”

After installing updates on Ubuntu 14.04.1 LTS, an error with the text began to appear daily:

/etc/cron.daily/amavisd-new:
Please run this cronjob as user amavis
run-parts: /etc/cron.daily/amavisd-new exited with return code 1

The reason was the update of amavis and the migration when updating the configuration file /etc/cron.daily/amavisd-new in /etc/cron.d/amavisd-new, and for some reason the old file was not deleted.

As a result, the solution to this problem – make sure that the configuration file /etc/cron.d/amavisd-new is present and delete the old file /etc/cron.daily/amavisd-new.

How to turn on the iPhone if the button does not work

To turn on the iPhone without a power button, just connect it with a USB cable to your computer.

If the iPhone does not turn on immediately, the battery is likely to be completely depleted, in which case it will be necessary to wait about 10 minutes until it has enough charge to turn on, after which the iPhone will turn on.

Setting up a network in Windows via the command line

To begin, open the command line by clicking on the shortcut in the Start menu or typing the command “cmd” in the “Run” line.

Here is an example of viewing the current configuration:

netsh interface ip show config

View a list of network interfaces:

netsh interface ipv4 show interfaces

An example of configuring static parameters for an interface named Ethernet 2:

netsh interface ip set address name="Ethernet 2" static 192.168.0.101 255.255.255.0 192.168.0.1 1

Or so:

netsh interface ipv4 set address name="Ethernet 2" source=static address=192.168.1.2 mask=255.255.255.0 gateway=192.168.1.1
netsh interface ipv4 add dnsserver name="Local" address=8.8.8.8 index=1

Example of obtaining parameters for the Ethernet 2 interface by DHCP:

netsh interface ip set address name="Ethernet 2" dhcp

Example of obtaining the DNS parameters for the Ethernet 2 interface by DHCP:

netsh interface ip set dns "Ethernet 2" dhcp

Export the current configuration to a file:

netsh -c interface dump > d:cfg1.txt

Importing a configuration from a file:

netsh -f d:cfg1.txt

Configuring Cloud in Mikrotik

Starting from the version of RouterOS v6.14, the Cloud function is added which allows using the Dynamic DNS name for a device that is automatically assigned and can be accessed by it even if the IP address is changed.

Example of switching through the console:

ip cloud set enabled=yes

Example of viewing parameters:

ip cloud print

Enable device time update with DDNS server time (if SNTP or NTP service is not configured):

ip cloud update-time yes/no

Immediate update of DDNS:

ip cloud force-update

View the DDNS name:

ip cloud dns-name

View the public IP address to which DDNS is bound:

ip cloud public-address

Binding DDNS to a local IP address instead of a public one, for example to 192.168.1.101, etc.)

ip cloud advanced use-local-address yes/no

View the current status of the Cloud (updated, updated, error, etc.):

ip cloud status

Through the graphical interface of the Cloud settings can be found in the menu “IP” – “Cloud”.