i've written bash scripts, beyond me , have no idea start. i'm running xubuntu. i'm using vpn allows me have forwarded port forwarded, running following line, produces output below, different port each time.
command: ./port_forward.sh user password output: loading port forward assignment information.. {"port:58661}
i'm looking make script runs process, takes port output, , puts configuration file deluge, , runs deluge. i've pasted current configuration below, 2 instances of 32157 need changed new port. file located @ /home/user/.config/deluge/core.conf
{ "file": 1, "format": 1 }{ "info_sent": 0.0, "lsd": true, "send_info": false, "move_completed_path": "/media/sf_storage2/download folder", "enc_in_policy": 1, "queue_new_to_top": false, "ignore_limits_on_local_network": true, "rate_limit_ip_overhead": true, "daemon_port": 58846, "natpmp": true, "max_active_limit": 8, "utpex": true, "max_active_downloading": 5, "max_active_seeding": 0, "allow_remote": false, "max_half_open_connections": 50, "download_location": "/media/sf_storage2/temp download folder", "compact_allocation": false, "max_upload_speed": -1.0, "cache_expiry": 60, "prioritize_first_last_pieces": false, "auto_managed": true, "enc_level": 2, "max_connections_per_second": 20, "dont_count_slow_torrents": true, "random_outgoing_ports": true, "max_upload_slots_per_torrent": -1, "new_release_check": false, "enc_out_policy": 1, "outgoing_ports": [ 0, 0 ], "seed_time_limit": 180, "cache_size": 512, "share_ratio_limit": 2.0, "max_download_speed": -1.0, "geoip_db_location": "/usr/share/geoip/geoip.dat", "torrentfiles_location": "/home/user/downloads", "stop_seed_at_ratio": false, "peer_tos": "0x00", "listen_interface": "", "upnp": true, "max_download_speed_per_torrent": -1, "max_upload_slots_global": 4, "enabled_plugins": [], "random_port": false, "autoadd_enable": false, "max_connections_global": 200, "enc_prefer_rc4": true, "listen_ports": [ 32157, 32157 ], "dht": true, "stop_seed_ratio": 2.0, "seed_time_ratio_limit": 7.0, "max_upload_speed_per_torrent": -1, "copy_torrent_file": false, "del_copy_torrent_file": false, "move_completed": true, "proxies": { "peer": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "web_seed": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "tracker": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 }, "dht": { "username": "", "password": "", "type": 0, "hostname": "", "port": 8080 } }, "add_paused": false, "max_connections_per_torrent": -1, "remove_seed_at_ratio": false, "autoadd_location": "/home/user/downloads", "plugins_location": "/home/user/.config/deluge/plugins" }
is possible? if there's way use output command, think store given port number in seperate file used script find , replace new port number, , change number in file next run.
eta:
thanks! wasn't quite sure how meant i'd new port, came this:
#!/bin/bash oldport=`cat core.conf | grep -a2 listen_ports | tail -n1` a=$(~/port_forward.sh user password) b=$(echo -e "$a" | sed -n '2p') port=`echo $b| cut -c9-13` sed -i 's/'$oldport'/'$port'/g' "core.conf" deluge-gtk %u
it works, though i'm there cleaner ways it. interested if there's way take whatever 5 digit number contained in output of port_forward.sh command , make variable. have above not ideal , break if output changed @ all. , yes, have 1 double quote, no idea why.
eta2: never mind, figured out. again help!
#!/bin/bash oldport=`cat core.conf | grep -a2 listen_ports | tail -n1` port=$(~/port_forward.sh user password| grep -o "[0-9][0-9][0-9][0-9][0-9]") sed -i 's/'$oldport'/'$port'/g' "core.conf" deluge-gtk %u
you can clean bit using parameter expansion/substring extraction. give following try. eliminates numerous 3rd party app calls along subshells spawn. don't have port_forward.sh
script test exact output, following should work based on have posted:
#!/bin/bash oldport=`grep -a2 listen_ports core.conf | tail -n1` a=$(~/port_forward.sh user password) tmp=${a##*port:} port=${tmp%\}*} sed -i 's/'$oldport'/'$port'/g' "core.conf" deluge-gtk %u
note how rearranged oldport
line. try , avoid uuoc (unnecessary use of cat
). if ever find doing cat |
, should tell there more appropriate way it. giving filename directly, using redirection, or use of herestring, or redirecting output of subshell... takes practice.