Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 20/05/2013, à 12:02

jean-luc5629

[Résolu] Commande sed pour substitution de textes variables

Bonjour;
J'ai besoin de votre aide pour l'utilisation de la commande sed pour la

modification de rtorrent.rc à chaque reconnexion vpn, mon niveau en bash étant au niveau du gaz de schiste...

IP changeante à chaque reconnexion , longueur variable....de l'IP...

je récupère la variable de la nouvelle IP <yyy.yy.yyy.yyy> par exemple : $IP
via script-security 2 et up.sh dans le fichier de config du client openvpn

jusque là pas de problèmes....

J'ai déjà utilisé la commande suivante dans d'autres cas pour substituer du textes fixes et non variables dans un fichier :

sed -i -e "s/mon texte 1/mon texte 2/g" /mon/chemin/monfichier.xxx

Mais là je bloque, j'ai essayé de l'adapter mais sans succès avec utilisation de jockers :
mon texte 1 =<bind = *> etc...

je voudrais pouvoir modifier la ligne :

bind = xxx.xxx.xxx.xxx par bind = yyy.yy.yyy.yyy a chaque reconnexion du vpn

xxx.xxx.xxx.xxx étant l'ancienne ip attribuée par le vpn ;yyy.yy.yyy.yyy la nouvelle


Merci d'avance.

Dernière modification par jean-luc5629 (Le 20/05/2013, à 15:38)

Hors ligne

#2 Le 20/05/2013, à 13:56

Hizoka

Re : [Résolu] Commande sed pour substitution de textes variables

Si ta ligne est exactement : bind = xxx.xxx.xxx.xxx

sed -i  "/^bind/ s/=.*/= ${IP}/" /mon/chemin/monfichier.xxx

Dernière modification par Hizoka (Le 20/05/2013, à 13:57)


KDE Neon 64bits
Tous mes softs (MKVExtractorQt, HizoSelect, HizoProgress, Qtesseract, Keneric, Services menus...) sont sur github

Hors ligne

#3 Le 20/05/2013, à 14:07

ljere

Re : [Résolu] Commande sed pour substitution de textes variables

tu peux passer par une variable

monip="dig +short myip.opendns.com @resolver1.opendns.com"
maderniereip="cat /tmp/monip"
sed -i -e "s/"$maderniereip"/"$monip"/g" /mon/chemin/monfichier.xxx
newip="dig +short myip.opendns.com @resolver1.opendns.com"
echo $newip > /tmp/monip

ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon

Hors ligne

#4 Le 20/05/2013, à 15:18

jean-luc5629

Re : [Résolu] Commande sed pour substitution de textes variables

Hizoka a écrit :

Si ta ligne est exactement : bind = xxx.xxx.xxx.xxx

sed -i  "/^bind/ s/=.*/= ${IP}/" /mon/chemin/monfichier.xxx

Ok; je te remercie, ça le fait

A+++
Jean luc

Hors ligne

#5 Le 20/05/2013, à 15:29

Hizoka

Re : [Résolu] Commande sed pour substitution de textes variables

un petit resolu dans ton titre de topic alors smile


KDE Neon 64bits
Tous mes softs (MKVExtractorQt, HizoSelect, HizoProgress, Qtesseract, Keneric, Services menus...) sont sur github

Hors ligne

#6 Le 21/05/2013, à 01:39

nesthib

Re : [Résolu] Commande sed pour substitution de textes variables

Tu peux aussi utiliser un fichier modèle avec envsubst ou un here document pour générer ton fichier de conf :

here document :

IP=yyy.yy.yyy.yyy
cat <<EOF
blabla du fichier de conf
bind = $IP
blabla
EOF >/…/rtorrent.rc

fichier modèle :

blabla du fichier de conf
bind = $IP
blabla
IP=yyy.yy.yyy.yyy
envsubst <fichier_modele >/…/rtorrent.rc

Bien sûr, au lieu d'écrire à la main ton IP=… tu peux remplacer par le retour de la commande qui te donne cette IP :

IP=$(commande_qui_retourne_l_ip)
envsubst …

GUL Bordeaux : GirollServices libres : TdCT.org
Hide in your shell, scripts & astuces :  applications dans un tunnelsmart wgettrouver des pdfinstall. auto de paquetssauvegarde auto♥ awk
  ⃛ɹǝsn xnuᴉꞁ uʍop-ǝpᴉsdn

Hors ligne

#7 Le 21/05/2013, à 11:33

jean-luc5629

Re : [Résolu] Commande sed pour substitution de textes variables

Bonjour;
Voilà comment j'ai fait:
1: fichier conf du vpn :

client
dev tun
proto udp
remote de-pp.tunsrv.s6n.net 443
resolv-retry infinite
nobind
persist-key
persist-tun
persist-remote-ip
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
mute-replay-warnings
ca arethusa-ca.crt
ns-cert-type server
cipher AES-256-CBC
comp-lzo
verb 3
mute 20
auth-user-pass pass
redirect-gateway def1
script-security 2
up up.sh
down down.sh

puis up.sh :

#!/bin/bash
/etc/openvpn/stoptorrent && killall checkvpn && sleep 5
export IP=$4
sed -i  "/^bind/ s/=.*/= ${IP}/" /home/user1/.rtorrent.rc
sed -i  "/^bind/ s/=.*/= ${IP}/" /home/user2/.rtorrent.rc
sed -i  "/^bind/ s/=.*/= ${IP}/" /home/user3/.rtorrent.rc
sed -i  "/^ client_bind/ s/=.*/= \"${IP}\"/" /home/user1/downloads/racine/mldonkey/downloads.ini
/etc/openvpn/starttorrent &
/etc/openvpn/checkvpn &

puis starttorrent:

#!/bin/bash
/etc/init.d/rtord1 restart
/etc/init.d/rtord2 restart
/etc/init.d/rtord3 restart
/etc/init.d/mldonkey-server restart

puis rtottent.rc :

scgi_port = 127.0.0.1:5000
encoding_list = UTF-8
bind = 10.16.0.90
port_range = 23951-23951
port_random = no
check_hash = no
directory = /home/user1/downloads/racine/torrents
session = /home/user1/.session
encryption = allow_incoming, try_outgoing, enable_retry
schedule = watch_directory,1,1,"load_start=/home/user1/downloads/racine/.watch/*.torrent"
schedule = untied_directory,5,5,"stop_untied=/home/user1/downloads/racine/.watch/*.torrent"
use_udp_trackers = yes
dht = off
peer_exchange = no
execute = {sh,-c,/usr/bin/php /var/www/rutorrent/php/initplugins.php user1 &}
max_peers = 50
min_peers_seed = -1
max_peers_seed = -1
max_uploads = 50
download_rate = 0
upload_rate = 0
schedule = low_diskspace,5,60,close_low_diskspace=256M

puis mldonkey (download.ini):

    (************************************)
    (*   Never edit options files when  *)
    (*       the daemon is running      *)
    (************************************)
    (* SECTION : Main *)
    (* Main options *)
    (************************************)



	(* small name of client *)
 client_name = debian


    (************************************)
    (* SECTION : Interfaces *)
    (* Options to control ports used by mldonkey interfaces *)
    (************************************)



	(* list of IP address allowed to connect to the core via telnet/GUI/WEB
	  for internal command set: list separated by spaces
	  example for internal command: set allowed_ips "127.0.0.0/8 192.168.1.2"
	  or for editing the ini-file: list separated by semi-colon
	  example for ini-file: allowed_ips = [ "127.0.0.0/8"; "192.168.1.2";]
	  CIDR and range notations are supported: ie use 192.168.0.0/24
	  or 192.168.0.0-192.168.0.255 for 192.168.0.* *)
 allowed_ips = [
  "127.0.0.1";
  "0.0.0.0";
  "0.0.0.0-255.255.255.255";]

	(* port for Graphical Interfaces, 0 to deactivate GUI interface *)
	(* changing this option requires restart of MLDonkey core *)
 gui_port = 4001

	(* port for GiFT Graphical Interfaces interaction. It was 1213, but the default is
	  now 0 for disabled, because it does not check for a password. *)
	(* changing this option requires restart of MLDonkey core *)
 gift_port = 0

	(* The port used to connect to your client with a web browser, 0 to deactivate web interface *)
	(* changing this option requires restart of MLDonkey core *)
 http_port = 4080

	(* port for user interaction, 0 to deactivate telnet interface *)
	(* changing this option requires restart of MLDonkey core *)
 telnet_port = 4000

	(* Aliases to commands. The alias (fist string) has to be
	  whitespaceless, the outcome of the alias (second string)
	  may have spaces (put it in quotation then). *)
 alias_commands = [
  (quit, q);
  (exit, q);]

	(* upnp port forwarding *)
	(* changing this option requires restart of MLDonkey core *)
 upnp_port_forwarding = false

	(* clear all upnp port forwarding before mldonkey exit *)
 clear_upnp_port_at_exit = true


    (************************************)
    (* SECTION : Bandwidth *)
    (* Bandwidth options *)
    (************************************)



	(* The maximal upload rate you can tolerate on your link in kBytes/s (0 = no limit)
	  The limit will apply on all your connections (clients and servers) and both
	  control and data messages. *)
 max_hard_upload_rate = 5

	(* The maximal download rate you can tolerate on your link in kBytes/s (0 = no limit)
	  The limit will apply on all your connections (clients and servers) and both
	  control and data messages. Maximum value depends on max_hard_upload_rate:
	  >= 10    -> unlimited download
	  < 10 > 3 -> download limited to upload * 4
	  < 4      -> download limited to upload * 3 *)
 max_hard_download_rate = 20

	(* Second maximal upload rate for easy toggling (use bw_toggle) *)
 max_hard_upload_rate_2 = 10

	(* Second maximal download rate for easy toggling (use bw_toggle) *)
 max_hard_download_rate_2 = 50

	(* Maximal number of opened connections *)
 max_opened_connections = 100

	(* Second maximal number of opened connections for easy toggling (use bw_toggle) *)
 max_opened_connections_2 = 200

	(* Amount of indirect connections in percent (min 30, max 70) of max_opened_connections *)
 max_indirect_connections = 30

	(* How many slots can be used for upload, minimum 3 *)
 max_upload_slots = 5

	(* How many percent of upload slots can be used for downloading files
	  tagged as release, maximum 75% *)
 max_release_slots = 20

	(* Set aside a single reserved slot to upload to friends *)
 friends_upload_slot = true

	(* Maximum file size to benefit from the reserved slot for small files (0 to disable) *)
 small_files_slot_limit = 10240

	(* Set this to true if you want to have dynamic upload slot allocation (experimental) *)
 dynamic_slots = false

	(* Maximal number of connections that can be opened per second *)
 max_connections_per_second = 5

	(* list of IP addresses allowed to connect to the core with no limit on
	  upload/download and upload slots.  List separated by spaces, wildcard=255
	  ie: use 192.168.0.255 for 192.168.0.*  *)
 nolimit_ips = [
  "127.0.0.1";]

	(* This option enables MLdonkey to always read as much data as possible
	  from a channel, but use more CPU as it must then copy the data in the
	  channel buffer. *)
 copy_read_buffer = true


    (************************************)
    (* SECTION : Networks *)
    (* Networks options *)
    (************************************)



	(* Set to true if you also want mldonkey to run as an overnet client
	  (enable_donkey must be true) *)
 enable_overnet = false

	(* Set to true if you also want mldonkey to run as an kademlia client
	  (enable_donkey must be true, and only experimental) *)
 enable_kademlia = true

	(* Set to true if you want mldonkey to connect to edonkey servers
	  (enable_donkey must be true, and only experimental) *)
 enable_servers = true

	(* Set to true if you also want mldonkey to run as an Bittorrent client *)
 enable_bittorrent = true

	(* Set to true if you also want mldonkey to run as a donkey client *)
 enable_donkey = true

	(* Set to true if you also want mldonkey to run as a napster client (experimental) *)
 enable_opennap = false

	(* Set to true if you also want mldonkey to run as a soulseek client (experimental) *)
 enable_soulseek = false

	(* Set to true if you also want mldonkey to run as a gnutella1 sub node (experimental) *)
 enable_gnutella = false

	(* Set to true if you also want mldonkey to run as a gnutella2 sub node (experimental) *)
 enable_gnutella2 = false

	(* Set to true if you also want mldonkey to run as a Fasttrack sub node (experimental) *)
 enable_fasttrack = false

	(* Set to true if you also want mldonkey to run as a direct-connect node (experimental) *)
 enable_directconnect = false

	(* Set to true if you also want mldonkey to download HTTP files (experimental) *)
 enable_fileTP = true


    (************************************)
    (* SECTION : Network Config *)
    (* Network config options *)
    (************************************)



	(* The last IP address used for this client *)
 client_ip = "212.117.165.227"

	(* Use the IP specified by 'client_ip' instead of trying to determine it
	  ourself. Don't set this option to true if you have dynamic IP. *)
 force_client_ip = false

	(* Use http://ip.discoveryvip.com/ip.asp to obtain WAN IP *)
 discover_ip = true

	(* User agent string (default = "default") *)
 user_agent = default

	(* A list of lines to download on the WEB: each line has
	  the format: (kind, period, url), where kind is either
	  'server.met' for a server.met file (also in gz/bz2/zip format)
	               containing ed2k server, or
	  'comments.met' for a file of comments, or
	  'guarding.p2p' for a blocklist file (also in gz/bz2/zip format), or
	  'ocl' for file in the ocl format containing overnet peers, or
	  'contact.dat' for an contact.dat file containing overnet peers,
	  'nodes.gzip' for a fasttrack nodes.gzip,
	  'hublist' for DirectConnect hubs list,
	  and period is the period between updates (in hours),
	  a period of zero means the file is only loaded once on startup,
	  and url is the url of the file to download.
	  IMPORTANT: Put the URL and the kind between quotes.
	  EXAMPLE:
	    web_infos = [
	    ("server.met", 0, "http://www.gruk.org/server.met.gz");
	    ("hublist", 0, "http://dchublist.com/hublist.xml.bz2");
	    ("guarding.p2p", 96, "http://www.bluetack.co.uk/config/level1.gz");
	    ("ocl", 24, "http://members.lycos.co.uk/appbyhp2/FlockHelpApp/contact-files/contact.ocl");
	    ("contact.dat", 168, "http://download.overnet.org/contact.dat");
	    ("geoip.dat", 168, "http://www.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz");
	    ]
	   *)
 web_infos = [
  ("geoip.dat", 0, "http://www.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz");
  ("server.met", 0, "http://www.gruk.org/server.met.gz");
  ("guarding.p2p", 96, "http://www.bluetack.co.uk/config/level1.gz");
  (hublist, 0, "http://dchublist.com/hublist.config.bz2");
  ("nodes.gzip", 0, "http://update.kceasy.com/update/fasttrack/nodes.gzip");]

	(* Cookies send with a http request (used for .torrent files and web_infos) *)
 referers = [
  (".*suprnova.*", "http://www.suprnova.org/");]

	(* Cookies send with a http request (used for .torrent files and web_infos) *)
 cookies = []

	(* Direct HTTP queries to HTTP proxy *)
 http_proxy_server = ""

	(* Port of HTTP proxy *)
 http_proxy_port = 8080

	(* HTTP proxy login (leave empty if proxy doesn't require authentication) *)
 http_proxy_login = ""

	(* HTTP proxy password *)
 http_proxy_password = ""

	(* Direct TCP connections to HTTP proxy (the proxy should support CONNECT) *)
 http_proxy_tcp = false


    (************************************)
    (* SECTION : HTML mods *)
    (* Options to configure HTML mode *)
    (************************************)



	(* bw_stats refresh delay (seconds) *)
 html_mods_bw_refresh_delay = 11

	(* html_mods_theme to use (located in relative html_themes/<theme_name> directory
	  leave blank to use internal theme *)
 html_mods_theme = ""


    (************************************)
    (* SECTION : Download *)
    (* Download options *)
    (************************************)



	(* Set to false if you don't want mldonkey to automatically put completed files
	  in incoming directory *)
 auto_commit = true

	(* Set to true if you want all new downloads be paused immediatly
	  will be set to false on core start. *)
 pause_new_downloads = false

	(* Set to true if you want to activate the release slot feature for all new downloads. *)
 release_new_downloads = false

	(* The maximal number of files in Downloading state (other ones are Queued) *)
 max_concurrent_downloads = 50

	(* The maximal length of zero bytes between non-zero bytes in a file that
	  should be interpreted as downloaded during a recovery *)
 max_recover_zeroes_gap = 16

	(* A command that is called when a file is committed, does not work on MinGW.
	  Arguments are (kept for compatibility):
	    $1 - temp file name, without path
	    $2 - file size
	    $3 - filename of the committed file
	  Also these environment variables can be used (preferred way):
	    $TEMPNAME  - temp file name, including path
	    $FILEID    - same as $1
	    $FILESIZE  - same as $2
	    $FILENAME  - same as $3
	    $FILEHASH  - internal hash
	    $DURATION  - download duration
	    $INCOMING  - directory used for commit
	    $NETWORK   - network used for downloading
	    $ED2K_HASH - ed2k hash if MD4 is known
	    $FILE_OWNER - user who started the download
	    $FILE_GROUP - group the file belongs to
	    $USER_MAIL - mail address of file_owner
	   *)
 file_completed_cmd = ""

	(* The command which is called when a download is started. Arguments
	  are '-file <num>'
	  Also these environment variables can be used (preferred way):
	    $TEMPNAME  - temp file name, including path
	    $FILEID    - same as $1
	    $FILESIZE  - same as $2
	    $FILENAME  - same as $3
	    $FILEHASH  - internal hash
	    $NETWORK   - network used for downloading
	    $ED2K_HASH - ed2k hash if MD4 is known
	    $FILE_OWNER - user who started the download
	    $FILE_GROUP - group the file belongs to
	    $USER_MAIL - mail address of file_owner
	   *)
 file_started_cmd = ""


    (************************************)
    (* SECTION : Startup *)
    (* Startup options *)
    (************************************)



	(* The login of the user you want mldonkey to run as, after the ports
	  have been bound (can be used not to run with root privileges when
	  a port < 1024 is needed) *)
	(* changing this option requires restart of MLDonkey core *)
 run_as_user = mldonkey

	(* The UID of the user (0=disabled) you want mldonkey to run as, after the ports
	  have been bound (can be used not to run with root privileges when
	  a port < 1024 is needed) *)
	(* changing this option requires restart of MLDonkey core *)
 run_as_useruid = 115

	(* The group of run_as_user user to be used *)
	(* changing this option requires restart of MLDonkey core *)
 run_as_group = ""

	(* The group of run_as_user user to be used *)
	(* changing this option requires restart of MLDonkey core *)
 run_as_groupgid = 0

	(* Ask for GUI start *)
 ask_for_gui = false

	(* Automatically Start the GUI *)
 start_gui = false

	(* Should MLdonkey try to recover downloads of files in temp/ at startup *)
 recover_temp_on_startup = true


    (************************************)
    (* SECTION : Mail *)
    (* Mail options *)
    (************************************)



	(* The mail server you want to use (must be SMTP). Use hostname or IP address *)
 smtp_server = "127.0.0.1"

	(* The port to use on the mail server (default 25) *)
 smtp_port = 25

	(* Login to use for SMTP authentication (leave empty to disable). LOGIN, PLAIN and CRAM-MD5 methods are supported *)
 smtp_login = ""

	(* Password to use for SMTP authentication *)
 smtp_password = ""

	(* Email address to receive notifications when downloads are completed or disk is full (leave empty to disable, separate multiple addresses with space) *)
 mail = ""

	(* Set to false if your mail server cannot handle angle-brackets around addresses (RFC 5321) *)
 add_mail_brackets = true

	(* Send filename in mail subject *)
 filename_in_subject = true

	(* Put a prefix for the filename here which shows up in the notification mail *)
 url_in_mail = ""


    (************************************)
    (* SECTION : Paths *)
    (* Paths options *)
    (************************************)



	(* The directory where temporary files should be put *)
 temp_directory = temp

	(* How often (in minutes) should MLDonkey scan all shared directories for new/removed files.
	  Minimum 5, 0 to disable. Use command reshare to manually scan shares.
	  When core starts, shared directories are scanned once, independent of this option. *)
	(* changing this option requires restart of MLDonkey core *)
 share_scan_interval = 30

	(* New download files are created with these rights (in octal) *)
 create_file_mode = 664

	(* New directories in incoming_directories are created with these rights (in octal) *)
 create_dir_mode = 755

	(* Create new files as sparse (not supported on FAT volumes) *)
 create_file_sparse = true

	(* Mininum free space in MB on temp_directory, minimum 50 *)
 hdd_temp_minfree = 50

	(* If true core shuts down when free space on temp dir is below hdd_temp_minfree,
	  otherwise all downloads are paused and a warning email is sent. *)
 hdd_temp_stop_core = false

	(* Mininum free space in MB on core directory, minimum 20 *)
 hdd_coredir_minfree = 50

	(* If true core shuts down when free space on core dir is below hdd_coredir_minfree,
	  otherwise all downloads are paused and a warning email is sent. *)
 hdd_coredir_stop_core = true

	(* Send a warning mail each <interval> hours for each directory, 0 to deactivate mail warnings. *)
 hdd_send_warning_interval = 1

	(*                 Incoming and shared directories.
	   At least two entries have to be present here, one with strategy
	   incoming_files and one with strategy incoming_directories.
	   Both entries can point to the same directory.
	   If one of the two strategies is missing, MLDonkey will create a default
	   directory with its entry here.
	   Finished BT multifile downloads are committed to the first directory
	   with strategy incoming_directories. Other downloads are committed
	   to the first directory with the strategy incoming_files.
	   MLdonkey searches all shared_directories with incoming_* strategies
	   on commit and uses the first one with enough free diskspace.
	   Other strategies can be found in searches.ini, section customized_sharing. *)
 shared_directories = [
  {     dirname = shared
     strategy = all_files
     priority = 0
};
  {     dirname = "incoming/files"
     strategy = incoming_files
     priority = 0
};
  {     dirname = "incoming/directories"
     strategy = incoming_directories
     priority = 0
};]


    (************************************)
    (* SECTION : Security *)
    (* Security options *)
    (************************************)



	(* Commands that you are allowed to be call from the interface. These
	  commands should short, so that the core is not blocked more than necessary. *)
 allowed_commands = [
  (df, df);
  (ls, "ls incoming");]

	(* Allow you to use any command with ! in the interface instead of only the
	  ones in allowed_commands *)
 allow_any_command = false

	(* Allow others to browse our share list (0: none, 1: friends only, 2: everyone *)
 allow_browse_share = 1

	(* Regexp of messages to filter out, example: string1|string2|string3 *)
 messages_filter = "DI-Emule|ZamBoR|Ketamine|eMule FX|AUTOMATED MESSAGE|Hi Honey!|Do you live in my area|download HyperMule"

	(* Regexp of comments to filter out, example: string1|string2|string3 *)
 comments_filter = "http://|https://|www\\."


    (************************************)
    (* SECTION : Other *)
    (* Other options *)
    (************************************)



	(* (experimental) *)
 save_results = 0

	(* Buffer writes and flush after buffer_writes_delay seconds (experimental) *)
 buffer_writes = false

	(* build statistics about eMule mods *)
 emule_mods_count = false

	(* show all eMule mods in statistics *)
 emule_mods_showall = false

	(* How often (in hours) should a backup of the ini files be written into old_config.
	  A value of zero means that a backup is written only when the core shuts down. *)
 backup_options_delay = 0

	(* Define the total number of options archives in old_config. *)
 backup_options_generations = 10

	(* Define the format of the archive, zip or tar.gz are valid. *)
 backup_options_format = "tar.gz"

	(* The maximum time in seconds to wait for networks to cleanly shutdown. *)
 shutdown_timeout = 3

	(* The IP address used to bind the p2p clients *)
	(* changing this option requires restart of MLDonkey core *)
 client_bind_addr = "10.16.0.90"



(*****************************************************************)
(*                                                               *)
(*                       ADVANCED OPTIONS                        *)
(*                                                               *)
(*        All the options after this line are for the expert     *)
(*        user. Do not modify them if you are not   sure.        *)
(*                                                               *)
(*****************************************************************)





    (************************************)
    (* SECTION : Interfaces FOR EXPERTS *)
    (* Options to control ports used by mldonkey interfaces *)
    (************************************)



	(* The IP address used to bind the http server *)
	(* changing this option requires restart of MLDonkey core *)
 http_bind_addr = "0.0.0.0"

	(* The IP address used to bind the gui server *)
	(* changing this option requires restart of MLDonkey core *)
 gui_bind_addr = "0.0.0.0"

	(* The IP address used to bind the telnet server *)
	(* changing this option requires restart of MLDonkey core *)
 telnet_bind_addr = "0.0.0.0"

	(* Should *all* sources for a file be shown on HTML/telnet vd <num> *)
 print_all_sources = true

	(* Improved telnet interface *)
 improved_telnet = true

	(* A space-separated list of keywords. Each keyword triggers
	  printing information on the corresponding messages:
	  verb : verbose mode (interesting not only for coders)
	  mc : debug client messages
	  mr|raw : debug raw messages
	  mct : debug emule clients tags
	  ms : debug server messages
	  sm : debug source management
	  net : debug net
	  gui : debug gui
	  no-login : disable login messages
	  file : debug file handling
	  do : some download warnings
	  up : some upload warnings
	  unk : unknown messages
	  ov : overnet
	  loc : debug source research/master servers
	  share: debug sharing
	  md4 : md4 computation
	  connect : debug connections
	  udp : udp messages
	  ultra|super : debug supernode
	  swarming : debug swarming
	  hc : http_client messages
	  hs : http_server messages
	  com : commands by non-admin users
	  act : debug activity
	  bw : debug bandwidth
	  geo : debug GeoIP
	  unexp : debug unexpected messages
	  dht : debug DHT *)
 verbosity = ""


    (************************************)
    (* SECTION : Bandwidth FOR EXPERTS *)
    (* Bandwidth options *)
    (************************************)



	(* The delay in milliseconds to wait in the event loop. Can be decreased to
	  increase the bandwidth usage, or increased to lower the CPU usage. *)
 loop_delay = 5


    (************************************)
    (* SECTION : Networks FOR EXPERTS *)
    (* Networks options *)
    (************************************)



	(* Set to true if you also want mldonkey to run as a OpenFT sub node (experimental) *)
 enable_openft = false


    (************************************)
    (* SECTION : Network Config FOR EXPERTS *)
    (* Network config options *)
    (************************************)



	(* URLs of RSS feeds *)
 rss_feeds = []

	(* If MLDonkey can not read broken RSS feeds, use this program to preprocess them *)
 rss_preprocessor = xmllint

	(* Keep IP blocking ranges descriptions in memory *)
 ip_blocking_descriptions = false

	(* IP blocking list filename (peerguardian format), can also be in gz/bz2/zip format
	  Zip files must contain either a file named guarding.p2p or guarding_full.p2p. *)
 ip_blocking = ""

	(* List of countries to block connections from/to (requires Geoip).
	  Names are in ISO 3166 format, see http://www.maxmind.com/app/iso3166
	  You can also at your own risk use "Unknown" for IPs Geoip won't recognize. *)
 ip_blocking_countries = []

	(* false: use ip_blocking_countries as block list, all other countries are allowed
	  true: use ip_blocking_countries as allow list, all other countries are blocked *)
 ip_blocking_countries_block = false

	(* Location of GeoIP.dat (Get one from http://www.maxmind.com/download/geoip/database/) *)
 geoip_dat = ""

	(* The size of the header of a TCP/IP packet on your connection (ppp adds
	  14 bytes sometimes, so modify to take that into account) *)
 tcpip_packet_size = 40

	(* The size of the MTU of a TCP/IP packet on your connection *)
 mtu_packet_size = 1500

	(* The size of the minimal packet you want mldonkey to send when data is
	  available on the connection *)
 minimal_packet_size = 600

	(* Should a connection check if the peer we are connected to is still alive?
	  This implies some bandwidth-cost (with 200 connections ~10-20%) *)
 socket_keepalive = false


    (************************************)
    (* SECTION : HTML mods FOR EXPERTS *)
    (* Options to configure HTML mode *)
    (************************************)



	(* Whether to use the modified WEB interface *)
 html_mods = true

	(* Which html_mods style to use (set with html_mods_style command) *)
 html_mods_style = 0

	(* Whether to use human readable GMk number format *)
 html_mods_human_readable = true

	(* Whether to use relative availability in the WEB interface *)
 html_mods_use_relative_availability = true

	(* Whether to display the Net column in vd output *)
 html_mods_vd_network = true

	(* Whether to display the Comments column in vd output *)
 html_mods_vd_comments = true

	(* Whether to display the User column in vd output *)
 html_mods_vd_user = false

	(* Whether to display the Group column in vd output *)
 html_mods_vd_group = false

	(* Whether to display the Active Sources column in vd output *)
 html_mods_vd_active_sources = true

	(* Whether to display the Age column in vd output *)
 html_mods_vd_age = true

	(* Whether to display flags instead of country codes *)
 html_flags = true

	(* Show graph in vd output *)
 html_mods_vd_gfx = true

	(* Remove graph files on core shutdown *)
 html_mods_vd_gfx_remove = false

	(* Fill graph in vd output *)
 html_mods_vd_gfx_fill = false

	(* Split download and upload graph in vd output *)
 html_mods_vd_gfx_split = false

	(* Stacked download and upload graph *)
 html_mods_vd_gfx_stack = true

	(* Flip up/side graph position in vd output *)
 html_mods_vd_gfx_flip = true

	(* Show mean line on graph in vd output *)
 html_mods_vd_gfx_mean = true

	(* Show transparent graph in vd output (only for png) *)
 html_mods_vd_gfx_transparent = true

	(* Draw graph as png if true, else draw as jpg in vd output *)
 html_mods_vd_gfx_png = true

	(* Show hourly graph in vd output *)
 html_mods_vd_gfx_h = true

	(* Graph x size in vd output ( 365 < x < 3665 ) *)
 html_mods_vd_gfx_x_size = 795

	(* Graph y size in vd output ( 200 < y < 1200 ) *)
 html_mods_vd_gfx_y_size = 200

	(* compute values for hourly graph every 1,2,3,4,5,10,15,20,30,60 min
		Changes to this option require a core restart. *)
	(* changing this option requires restart of MLDonkey core *)
 html_mods_vd_gfx_h_intervall = 60

	(* Dynamic grid width, start with 1 h/grid, maximum html_mods_vd_gfx_h_grid_time h/grid *)
 html_mods_vd_gfx_h_dymamic = true

	(* Max hours on time scale per grid (0 = no limit) *)
 html_mods_vd_gfx_h_grid_time = 0

	(* Number of shown subgrids on graph (0 = no subgrids) *)
 html_mods_vd_gfx_subgrid = 0

	(* Draw tag graph *)
 html_mods_vd_gfx_tag = false

	(* Use tag source image  *)
 html_mods_vd_gfx_tag_use_source = false

	(* Tag source image name *)
 html_mods_vd_gfx_tag_source = image

	(* Draw tag as png if true, else draw as jpg in vd output *)
 html_mods_vd_gfx_tag_png = true

	(* Enable tag graph title *)
 html_mods_vd_gfx_tag_enable_title = true

	(* Tag graph title *)
 html_mods_vd_gfx_tag_title = "MLNet traffic"

	(* Tag graph title x pos in vd output *)
 html_mods_vd_gfx_tag_title_x_pos = 4

	(* Tag graph title y pos in vd output *)
 html_mods_vd_gfx_tag_title_y_pos = 1

	(* Tag graph download x pos in vd output *)
 html_mods_vd_gfx_tag_dl_x_pos = 4

	(* Tag graph download y pos in vd output *)
 html_mods_vd_gfx_tag_dl_y_pos = 17

	(* Tag graph upload x pos in vd output *)
 html_mods_vd_gfx_tag_ul_x_pos = 4

	(* Tag graph upload y pos in vd output *)
 html_mods_vd_gfx_tag_ul_y_pos = 33

	(* Tag graph x size in vd output ( 130 < x < 3600 ) *)
 html_mods_vd_gfx_tag_x_size = 80

	(* Tag graph y size in vd output ( 50 < x < 1200 ) *)
 html_mods_vd_gfx_tag_y_size = 50

	(* Whether to display the Last column in vd output *)
 html_mods_vd_last = true

	(* Whether to display the Priority column in vd output *)
 html_mods_vd_prio = true

	(* Change height of download indicator bar in vd output *)
 html_vd_barheight = 2

	(* Whether to display chunks list as graph or text in vd output *)
 html_vd_chunk_graph = true

	(* Change style of chunk graph *)
 html_vd_chunk_graph_style = 0

	(* Change max width of chunk graph *)
 html_vd_chunk_graph_max_width = 200

	(* Whether to display the pending slots in uploaders command *)
 html_mods_show_pending = true

	(* Whether to load the mldonkey_messages.ini file (false=use internal settings) *)
 html_mods_load_message_file = false

	(* Maximum chat messages to log in memory *)
 html_mods_max_messages = 50

	(* Whether to use checkboxes in the WEB interface for download list *)
 html_checkbox_vd_file_list = true

	(* Whether to use checkboxes in the WEB interface for search result list *)
 html_checkbox_search_file_list = false

	(* Use gzip compression on web pages *)
 html_use_gzip = false

	(* Whether to use the fancy javascript tooltips or plain html-title *)
 html_mods_use_js_tooltips = true

	(* How long to wait before displaying the tooltips *)
 html_mods_js_tooltips_wait = 0

	(* How long to display the tooltips *)
 html_mods_js_tooltips_timeout = 100000

	(* Use javascript to display option help text as js popup (true=use js, false=use html tables) *)
 html_mods_use_js_helptext = true


    (************************************)
    (* SECTION : Debug FOR EXPERTS *)
    (* Debug options *)
    (************************************)



	(* If this option is set, IP addresses on the local network are allowed *)
 allow_local_network = false

	(* size of log in number of records *)
 log_size = 300

	(* Maximum size of log_file in MB, this value is only checked on startup,
	   log_file will be deleted if its bigger than log_file_size. *)
 log_file_size = 2

	(* The file in which you want mldonkey to log its debug messages. If you
	  set this option, mldonkey will log this info in the file until you use the
	  'close_log' command. The log file may become very large. You can
	  also enable logging in a file after startup using the 'log_file' command. *)
 log_file = "/var/log/mldonkey/mlnet.log"

	(* Post log messages to syslog. This setting is independent of log_file
	  and its associated commands, therefore close_log does not stop log to syslog.
	  Its therefore possible to log to syslog and log_file at the same time. *)
 log_to_syslog = false

	(* number of lines for GUI console messages *)
 gui_log_size = 30


    (************************************)
    (* SECTION : Download FOR EXPERTS *)
    (* Download options *)
    (************************************)



	(* How many sources to use to download each chunk *)
 sources_per_chunk = 3


    (************************************)
    (* SECTION : Startup FOR EXPERTS *)
    (* Startup options *)
    (************************************)



	(* How many megabytes should MLdonkey keep for saving configuration files. *)
	(* changing this option requires restart of MLDonkey core *)
 config_files_security_space = 10


    (************************************)
    (* SECTION : Paths FOR EXPERTS *)
    (* Paths options *)
    (************************************)



	(* Name of program used for preview (first arg is local filename, second arg
	  is name of file as searched on eDonkey *)
 previewer = "/usr/bin/see"

	(* Directory where mldonkey binaries are installed *)
 mldonkey_bin = "/usr/bin"

	(* Name of GUI to start *)
 mldonkey_gui = "/usr/bin/mlgui"


    (************************************)
    (* SECTION : Other FOR EXPERTS *)
    (* Other options *)
    (************************************)



	(* Buffer writes and flush after buffer_writes_delay seconds (experimental) *)
	(* changing this option requires restart of MLDonkey core *)
 buffer_writes_delay = 30.

	(* Flush buffers if buffers exceed buffer_writes_threshold kB (experimental) *)
 buffer_writes_threshold = 1024

	(* The conversions to apply on Unicode characters *)
 utf8_filename_conversions = []

	(* The size of the buffer between the client and its GUI. Can be useful
	  to increase when the connection between them has a small bandwith *)
 interface_buffer = 1000000

	(* The size long names will be shortened to in the interface *)
 max_name_len = 50

	(* The size filenames will be shortened to in search results *)
 max_result_name_len = 50

	(* The maximum number of different filenames used by MLDonkey *)
 max_filenames = 50

	(* The size long client names will be shortened to in the interface *)
 max_client_name_len = 25

	(* Is the default terminal an ANSI terminal (escape sequences can be used) *)
 term_ansi = true

	(* Delay between updates to the GUI *)
 update_gui_delay = 1.

	(* The realm shown when connecting with a WEB browser *)
 http_realm = MLdonkey

	(* This option controls whether the WEB interface should show frame borders or not *)
 html_frame_border = true

	(* The height of the command frame in pixel (depends on your screen and browser sizes) *)
 commands_frame_height = 46

	(* Message printed at startup additional to welcome text *)
 motd_html = ""

	(* Force compaction every <n> hours (in [1..24]) *)
 compaction_delay = 2

	(* The delay between reloads of the vd output in the WEB interface *)
 vd_reload_delay = 120

	(* Should the MLSUBMIT.REG file be created *)
 create_mlsubmit = true

	(* Size of the minor heap in kB *)
 minor_heap_size = 32

	(* The source queues to display in source lists (see 'sources' command) *)
 relevant_queues = [
  0;
  1;
  2;
  3;
  4;
  5;
  6;
  8;
  9;
  10;]

	(* The minimal delay between two connections to the same client (in seconds) *)
 min_reask_delay = 600

	(* Whether to display results already downloaded *)
 display_downloaded_results = true

	(* Minimal number of results for filter form to appear *)
 filter_table_threshold = 50

	(* Maximal size in byte of the buffers of a client, minimum 50.000 byte.
	For high-volume links raise this value to 1.000.000 or higher. *)
 client_buffer_size = 500000

	(* The delay between two saves of the 'downloads.ini' file (default is 15 minutes).
	  Changes to this option require a core restart. *)
	(* changing this option requires restart of MLDonkey core *)
 save_options_delay = 900.

	(* timeout when connecting to a server *)
 server_connection_timeout = 30.

	(* The delay between one glance at a file and another *)
	(* changing this option requires restart of MLDonkey core *)
 download_sample_rate = 1.

	(* How many samples go into an estimate of transfer rates *)
 download_sample_size = 100

	(* This option defines a set of date at which some commands have to be executed.
	  For each tuple, the first argument is a list of week days (from 0 to 6),
	  the second is a list of hours (from 0 to 23) and the last one a command to
	  execute. Can be used with 'pause all' and 'resume all' for example to
	  resume and pause downloads automatically for the night. *)
 calendar = []

	(* The percentage of free memory before a compaction is triggered *)
 compaction_overhead = 25

	(* The major GC speed is computed from this parameter. This is the memory
	  that will be "wasted" because the GC does not immediatly collect 
	  unreachable blocks. It is expressed as a percentage of the memory used
	  for live data. The GC will work more (use more CPU time and collect 
	  blocks more eagerly) if space_overhead is smaller. *)
 space_overhead = 80

	(* Maximal number of results displayed for a search *)
 max_displayed_results = 1000

	(* (internal option) *)
	(* Do not change this option, internal use only! *)
 options_version = 22

	(* Maximum number of comments per file *)
 max_comments_per_file = 100

	(* Maximum length of file comments *)
 max_comment_length = 256

et checkvpn :

#!/bin/bash
sleep 60
min=60
max=300
#On fait un ping vers www.google.com toutes les 5min max, et si aucun paquet n'est reçu en retour (0 packets received, le 0 étant à la position 23 sur la ligne venant de ping) on relance le VPN
#"

while [ 1 > 0 ]; do
nb=$[($RANDOM % ($[$max - $min] + 1)) + $min]
        sleep $nb
	T=`ping -I $IP -c 1 www.google.com |grep "packets transmitted"`
	if [[ ${T:23:1} != "1" ]]
	then 
			echo `date` "--" "T= "$T >> /var/log/vpnlog-checkvpn && vpninit && exit
		
fi

done

openvpn étant lancé par run.sh en tache cron "if ! ( ps -e | grep run.sh) > /dev/null;then /etc/openvpn/run.sh; fi"; choisissant aléatoirement un point de connexion .conf d'openvpn.

#!/bin/bash
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
p0=/etc/openvpn/_
p1=/etc/openvpn/*.conf
p2=/etc/openvpn/clients/
p3=.conf
min=1
max=16
sleep 10
while [ 1 > 0 ]; do
nb=$[($RANDOM % ($[$max - $min] + 1)) + $min]
VPNOK=$(ip addr show tun0 | grep inet | wc -l)
if [ "$VPNOK" -ne "1" ]
then rm $p1 && cp $p2$nb $p0$nb$p3 && vpninit && vpnf=$(($vpnf+1)) && echo `date` "--" "vpnok= "$VPNOK "--" "vpnf ="$vpnf>> /var/log/vpnlog-run
  
  else vpnf=0
fi
if [ "$vpnf" = "10" ]
	then echo `date` "--" "vpnf= "$vpnf >> /var/log/vpnlog-stop && /sbin/reboot & 
fi
sleep 60

done

vpninit faisant un /etc/init.d/openvpn restart; down.sh fermant les sessions torrent et mldonkey

Si ça peut donner des idées....et si possible d'améliorer je suis preneur ( serveur de download installé sur une cubieboard (raspberry pi) avec + de ram et connexion sata.
A++++

Dernière modification par jean-luc5629 (Le 21/05/2013, à 16:23)

Hors ligne

#8 Le 21/05/2013, à 14:13

ljere

Re : [Résolu] Commande sed pour substitution de textes variables

personnellement je n'utilise que 2 scripts et pas besoin d’être en root
je lance donc au démarrage mes scripts

sh -c '~/script/script-vpn' &
sleep 60
sh -c '~/script/demon-vpn' &

demon-vpn    # changer 00.000.000.00 par votre adresse ip public

#! /bin/bash

# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe

while true
do
    sleep 5
    log=/tmp/demon-log
    ipnonprotege="00.000.000.00"
    monip=`dig +short myip.opendns.com @resolver1.opendns.com`
    maderniereip=`cat /tmp/monip`
    PING=$(ping -c 2 freedom-ip.com | grep % | cut -d ' ' -f4)

    if [[ "$monip" != "$maderniereip" || "$ipnonprotege" = "$maderniereip" || -z $PING ]];
    then
    (
	echo Pas de connexion Internet fonctionnelle		
	notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
        # L'adresse IP a changé, on lance une reconnexion du vpn
        VPN_STAT=$(nmcli con status | grep freedomip | cut -d\  -f 1)
        nmcli con down id "${VPN_STAT}"
    sleep 20
        nmcli con down id connexion filaire 1
    sleep 20
        nmcli con up id connexion filaire 1
    sleep 30
        sh -c '~/script/script-vpn'
    ) 2>&1 | tee -a $log
    fi
done

script-vpn

#!/bin/bash
# FREEDOM-IP AUTO CONNECT SCRIPT

echo "" > /tmp/monip
# ANALYSE INTERFACE RÉSEAU ACTIVE
echo
echo ----- ANALYSE INTERFACE RÉSEAU
NET_STAT=$(nmcli con status | egrep eth0)
echo
echo $NET_STAT est la connexion active


# VÉRIFICATION D'ÉTABLISSEMENT COMPLET DE LA CONNECTIVITÉ INTERNET
echo
echo ----- VÉRIFICATION INTERNET...
CURRENT_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
PING=$(ping -c 3 freedom-ip.com | grep % | cut -d ' ' -f4)
echo
echo Adresse IP actuelle: $CURRENT_IP
echo
echo $PING sur 3 paquets reçus depuis freedom-ip.com
if [ -z $PING ]; then
	echo
	echo Pas de connexion Internet fonctionnelle		
	notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
	exit
fi

# OCCUPATION DES SERVEURS
echo
echo ----- OCCUPATION DES SERVEURS
wget --no-check-certificate -O /tmp/fip_occupation https://freedom-ip.com/statistiques.php
SERV_LOAD=$(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR/d')
echo
echo $SERV_LOAD

SERV_MAX_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR/d' | sort -n | tail -n1) | cut -d ' ' -f2 | cut -d '
' -f1)
echo
echo $SERV_MAX_LOAD est le plus occupé, sélection pour connexion
notify-send 'Freedom-IP:' "Séléction du serveur le plus occupé: $SERV_MAX_LOAD" -i dialog-information


SERV_MAX_LOAD_2=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n2) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_3=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n3) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_4=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n4) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_5=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n5) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_6=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n6) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_7=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n7) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_8=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n8) | cut -d ' ' -f2 | cut -d '
' -f1)

SERV_MAX_LOAD_9=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n9) | cut -d ' ' -f2 | cut -d '
' -f1)


# VÉRIFICATION D'UNE CONNEXION AU VPN DÉJÀ EXISTANTE
echo
echo ----- VERIFICATION
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\  -f 1)
if [ -n "${VPN_STAT}" ]; then
echo
echo Déjà connecté à $VPN_STAT - Redémarrage avec $SERV_MAX_LOAD
notify-send 'Freedom-IP:' "Déjà connecté à $VPN_STAT, Reconnexion" -i dialog-warning	

echo
echo ----- DÉCONNEXION DE $VPN_STAT
nmcli con down id "${VPN_STAT}"
echo
echo OK
echo
echo ----- RECONNEXION À $SERV_MAX_LOAD'_freedomip'
echo
RCON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $RCON
	if [ "$RCON" = "Connexion activée" ]; then
	sleep 15
	notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
	echo
	echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
	notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error

		sleep 20
		RCON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
		echo $CON_2
		if [ "$CON_2" = "Connexion activée" ]; then
		sleep 15
		notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
		echo
		echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
		notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error

			sleep 20
			CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
			echo $CON_3
			if [ "$CON_3" = "Connexion activée" ]; then
			sleep 15
			notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
			echo
			echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
			notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error

				sleep 20
				CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
				echo $CON_4
				if [ "$CON_4" = "Connexion activée" ]; then
				sleep 15
				notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
				echo
				echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
				notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error

					sleep 20
					CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
					echo $CON_5
					if [ "$CON_5" = "Connexion activée" ]; then
					sleep 15
					notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
					echo
					echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6	
					notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error

						sleep 20
						CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
						echo $CON_6
						if [ "$CON_6" = "Connexion activée" ]; then
						sleep 15
						notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
						echo
						echo Impossible de se connecter à $SERV_MAX_LOAD_6
						echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
						notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning


						fi
					fi
				fi
			fi

		fi
	fi
	NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
	echo $NEW_IP > /tmp/monip
	echo Ancienne IP: $CURRENT_IP
	echo Nouvelle IP: $NEW_IP
	echo
	echo ----- FIN DE SCRIPT
	exit; else

echo
echo Pas de connexion VPN active
notify-send 'Freedom-IP:' "Établissement de la connexion sécurisée..." -i dialog-warning
fi


# CONNECTION AU VPN SI INTERNET CONNECTÉ
if [ $PING -eq 3 ]; then
echo
echo ----- CONNEXION À $SERV_MAX_LOAD
echo
CON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $CON
	if [ "$CON" = "Connexion activée" ]; then
	sleep 15
	notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
	echo
	echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
	notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error

		sleep 20
		CON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
		echo $CON_2
		if [ "$CON_2" = "Connexion activée" ]; then
		sleep 15
		notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
		echo
		echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
		notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error

			sleep 20
			CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
			echo $CON_3
			if [ "$CON_3" = "Connexion activée" ]; then
			sleep 15
			notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
			echo
			echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
			notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error

				sleep 20
				CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
				echo $CON_4
				if [ "$CON_4" = "Connexion activée" ]; then
				sleep 15
				notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
				echo
				echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
				notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error

					sleep 20
					CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
					echo $CON_5
					if [ "$CON_5" = "Connexion activée" ]; then
					sleep 15
					notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
					echo
					echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6	
					notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error

						sleep 20
						CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
						echo $CON_6
						if [ "$CON_6" = "Connexion activée" ]; then
						sleep 15
						notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
						echo
						echo Impossible de se connecter à $SERV_MAX_LOAD_6
						echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
						notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning



						fi
					fi
				fi
			fi

		fi
	fi
fi

NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
echo $NEW_IP > /tmp/monip
echo Ancienne IP: $CURRENT_IP
echo Nouvelle IP: $NEW_IP
echo
echo ----- FIN DE SCRIPT
exit

le bonus
si tu veux le log de network manager (pas obligatoire)

gksudo gedit /etc/NetworkManager/dispatcher.d/02log
#!/bin/bash

date >> /tmp/network-manager.log
echo "$0" "$@" >> /tmp/network-manager.log
sudo chmod +x /etc/NetworkManager/dispatcher.d/02log

ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon

Hors ligne

#9 Le 21/05/2013, à 17:20

jean-luc5629

Re : [Résolu] Commande sed pour substitution de textes variables

@ ljere

Je n'utilise pas network manager, le serveur de téléchargement est sur une cubieboard avec une debian whezzy nue (sans graphique) que je manage via ssh (putty & filezilla ou winscp + apache pour rutorrent ); donc je n'ouvre pas de session utilisateur, donc les softs sont lancés au démarrage de la cubieboard, les sessions utilisateurs ne servent qu'a pouvoir ouvrir 3 sessions rtorrent (moi + mes 2 enfants); rtorrent et transmission sont les seuls softs torrents que j'ai trouvé qui admettent un bind sur l'ip du vpn ainsi que mldonkey, avec amule pas possible à ma connaissance.Le fichier run.sh lance le vpn et vérifie toutes les minutes la présence de l'interface tun0 du vpn, si la connexion échoue au niveau d'un serveur, il en choisi un autre aléatoirement jusque ce que la connexion se fasse; l'avantage que je trouve au fait du bind des logiciels p2p sur l'ip locale du vpn, c'est qu'en cas d'un out du vpn, il ne peut plus y avoir la moindre connexion sur le p2p l'ip n'existant plus, et en plus j'ai rajouté un firewall inspiré de celui de mastergerb sur ce forum :http://forum.ubuntu-fr.org/viewtopic.php?pid=3492097#p3492097
; plusieurs scripts, mais que 2 qui tournent en permanence; un pour la vérif de l'interface vpn, l'autre pour le ping qui teste le traffic.
et ça me laisse encore beaucoup de ressources de disponible :
mini_130521051931128537.png

Je remercie Hizoka; car j'étais bloqué au niveau de la commande sed.

Merci et A+++

Dernière modification par jean-luc5629 (Le 21/05/2013, à 17:30)

Hors ligne

#10 Le 21/05/2013, à 17:44

ljere

Re : [Résolu] Commande sed pour substitution de textes variables

pas de souci je me doute bien que mes scripts ne correspondent pas à ta config c'est juste pour te donner des idées si tu as besoin,
question pare-feu j'ai pris la même base aussi, puis j'ai ajouté deux trois trucs


ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon

Hors ligne

#11 Le 21/05/2013, à 18:14

jean-luc5629

Re : [Résolu] Commande sed pour substitution de textes variables

Merci;
De plus nous n'utilisons pas le même vpn; freedom.ip à l'avantage d'être gratuit; mais hélas n'offre pas (ou n'offrait pas il y a quelques temps) de ports ouverts pour le p2p, ce qui fait que je me suis tourné vers une solution payante.
Merci à la communauté ubuntu, on y trouve tout sur le système linux, et surtout l'aide de personnes dévouées et ce très rapidement, je n'ai jamais été déçu.

Merci encore à tous.

Jean Luc

Hors ligne