30
submitted 2 days ago* (last edited 1 day ago) by sartaj@lemmy.world to c/linux@lemmy.ml

I have a laptop and a phone in which termux is installed. I want to move files from my phone to my computer using rsync if all files are older than 30 days. I think I should use find command with -exec rsync.

find . -mtime +30 -exec rsync something 

but the problem is my phone's IP address is always changing so how do I transfer file? I have to run this script in my laptop

solution

i wrote a script which move files and runs in my laptop

  1. i can't use hostname because I am on android 9 and don't want to install anything else.
  2. most of the time I am offline so using any internet service is not a good idea ( my devices are connected in themselves )

here is my script

#!/usr/bin/bash

#checking if script not already running and exit if already running
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :

set -e

TARGET_MAC="d2:1c:3c:3d:6a:a7"
RSYNC_LOG="$HOME/log/rsync_log.txt"  # Rclone log file


function get_ip() {
  # need to edit sudoers file to run 	sudo nmap -sn 192.168.43.0/24 without password
  # Allow members of group sudo to execute any command
  # %sudo	ALL=(ALL:ALL) ALL
  # 'username' ALL=(ALL) NOPASSWD: /usr/bin/nmap -sn 192.168.43.0/24


	sudo nmap -sn 192.168.43.0/24 | grep --before-context=3 -i "$TARGET_MAC" | tail -n 3 | head -n 1 | awk '{ print $6 }' | sed 's/[()]//g'; }


# run command only if wifi is connected
if echo $(nmcli general status) | grep -q -w "connected" ; then

  # for ssh to work in a changing IP address, a configuration line has to be enabled so that it does not ask for yes/no while connecting to a changed ip address
	TARGET_IP=$(get_ip)
  ssh -p 8022  "$TARGET_IP" 'find /data/data/com.termux/files/home/storage/shared/Pictures/ -mtime +30  -type d,f -printf %P\\0' | rsync --append --update --times --atimes --mkpath --verbose --human-readable --remove-source-files --log-file="$HOME/log/synced.log" --exclude='.dtrash' --files-from=- --from0  -e "ssh -p 8022" "$TARGET_IP":/data/data/com.termux/files/home/storage/shared/Pictures/ $HOME/Pictures
you are viewing a single comment's thread
view the rest of the comments
[-] Xanza@lemm.ee 6 points 2 days ago* (last edited 2 days ago)

VPN.. This is a specific problem that VPNs were created to solve.

On your Wireguard network (or whichever), note your vLAN IPs, and configure rclone/rsync with them like normal. Ensure you're connected to Wireguard and then run your command;

❯ fd --change-older-than 30days -X rclone sync phone:my/path/here pc:destination/path/here

Using a VPN ensures that regardless of WiFi/Cellular connections you'll still be able to transfer at home, or remotely. Using methods like hostnames only work locally.

[-] sartaj@lemmy.world 1 points 1 day ago

i use my phone's hotspot to connect to laptop

[-] Xanza@lemm.ee 1 points 1 day ago

Seems dubious, and will only work locally..

this post was submitted on 14 May 2025
30 points (100.0% liked)

Linux

54200 readers
527 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS