Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
fuss:linux [2020/02/25 05:07] – [Determining the Last Power On Method] officefuss:linux [2020/05/12 23:36] – [Scraping a Site Automatically using SystemD] office
Line 1118: Line 1118:
 In doing so, the power management issue seems to be resolved. In doing so, the power management issue seems to be resolved.
  
 +====== Automatically Add all RNDIS Devices to a Bridge ======
  
 +Edit or create the file at ''/etc/udev/rules.d/70-persistent-net.rules'' with the following contents:
 +<code>
 +SUBSYSTEM=="net", ACTION=="add", ATTRS{idProduct}=="a4a2", ATTRS{idVendor}=="0525", RUN+="/bin/sh -c '/sbin/ip link set dev %k up && /sbin/brctl addif br0 %k'"
 +</code>
 +where:
 +  * ''br0'' is the interface name of the bridge that the RNDIS devices will be added to.
  
 +followed by the command:
 +<code bash>
 +udevadm control --reload
 +</code>
  
 +to reload all udev rules.
  
 +The reason this works is due to ''a4a2'' and ''0525'' respectively being the identifiers for the RNDIS driver and not for the device itself. For instance, by issuing:
 +<code bash>
 +udevadm info -a /sys/class/net/usb0
 +</code>
  
 +will show at the top the RNDIS device without any identifiers whereas the parent ''RNDIS/Ethernet Gadget'' matches the identifiers.
  
 +One usage case for this rule is to connect a bunch of RNDIS devices to an USB hub and have them join the network automatically as they are hotplugged; for instance, Raspberry Pis [[fuss/raspberry_pi#logging-in_via_ssh_over_usb|can be configured as USB gadgets]] and then connected to an USB hub.
  
 +====== Scraping a Site Automatically using SystemD ======
 +
 +FTP sites can be scraped elegantly by using systemd and tmux on Linux. By starting a ''tmux'' detached terminal, ''wget'' can run in the background and download a website entirely whilst also allowing the user to check up on the progress by manually attaching and detaching from ''tmux''.
 +
 +The following script contains a few parameters underneath the ''Configuration'' comment and up to ''Internals'' in order to set:
 +  * the download path (''DOWNLOAD_DIRECTORY''),
 +  * the ''wget'' download URL (all protocols supported by ''wget'' such as FTP or HTTP) (''DOWNLOAD_URL''),
 +  * a descriptive name for the ''tmux'' session (''TMUX_SESSION_NAME'')
 +
 +<code bash>
 +[Unit]
 +Description=Scrape FTP Site
 +Requires=network.target local-fs.target remote-fs.target
 +After=network.target local-fs.target remote-fs.target
 +
 +[Install]
 +WantedBy=multi-user.target
 +
 +[Service]
 +# Configuration
 +Environment=DOWNLOAD_DIRECTORY="/path/to/directory"
 +Environment=DOWNLOAD_URL="ftp://somesite.tld/somedirectory"
 +Environment=TMUX_SESSION_NAME="somesite.tld-download"
 +# Internals
 +Type=oneshot
 +KillMode=none
 +User=root
 +ExecStartPre = -/bin/mkdir -p \""$DOWNLOAD_DIRECTORY"\"
 +ExecStart=/usr/bin/tmux new-session -d -c "\"$DOWNLOAD_DIRECTORY\"" -s "$TMUX_SESSION_NAME" -n "$TMUX_SESSION_NAME" "/usr/bin/wget -c -r \"$DOWNLOAD_URL\" -P \"$DOWNLOAD_DIRECTORY\""
 +ExecStop=/usr/bin/tmux send-keys -t "$TMUX_SESSION_NAME" C-c
 +RemainAfterExit=yes
 +
 +</code>
 +
 +The file should be placed under ''/etc/systemd/system'', then systemd has to be reloaded by issuing ''systemctl daemon-reload'', the service should then be loaded with ''systemctl enable SERVICE_FILE_NAME'' where ''SERVICE_FILE_NAME'' is the name of the file copied into ''/etc/systemd/system'' and finally started by issuing ''systemctl start SERVICE_FILE_NAME''.
 +
 +Upon every reboot, the service file will create a detached tmux terminal and start scraping files from the URL.

fuss/linux.txt · Last modified: 2024/02/21 06:47 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.