1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Linux Pipe into Proxmox LXC?

Discussion in 'Software' started by wyx087, 30 Jul 2024.

  1. wyx087

    wyx087 Multimodder

    Joined:
    15 Aug 2007
    Posts:
    12,068
    Likes Received:
    746
    I had to re-install my Proxmox box to another machine because the motherboard died.

    I have this alias I'm trying to restore.
    Code:
    alias rdip='readip ; echo "-- ^ local - v VPN --" ; echo "curl icanhazip.com" > /mnt/dl/pipe ; sleep 1 ; tail -n 1 /mnt/ramdisk/pipe_out.txt '
    
    Key bit:
    Code:
    echo "curl icanhazip.com" > /mnt/dl/pipe
    What could possibly be in /mnt/dl/pipe ?? It appears by sending command to this pipe file, it executes in the LXC container.

    My internet searching is failing me, only found a python script. Help me Bit-tech, you are my only hope :p
     
  2. wyx087

    wyx087 Multimodder

    Joined:
    15 Aug 2007
    Posts:
    12,068
    Likes Received:
    746
    Ah okay, I found the script inside the LXC responsible:

    Code:
    #!/bin/bash
    while true; do eval "$(cat /mnt/dl/pipe )" &> /mnt/ramdisk/pipe_out.txt; done
    So inside the LXC there is a script constantly running, looking for commands in /mnt/dl/pipe.
    Host (or anything has access to this mounted drive) write command into that file.
    LXC script writes the return into pip_out.txt.
    Host prints it out.

    So it was working, except curl behaves differently in the pipe. I don't get the IP in pipe_out.txt, I get a load of stats.
    Code:
     tail /mnt/ramdisk/pipe_out.txt
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    Any idea why?
    Running the command ("curl icanhazip.com") directly in the LXC shell do return IP.

    -----EDIT:
    Found why, the hostpipe.sh script had &> instead of >.
    Curl prints out the progress meter as stderr, which gets redirected into the txt file via &>

    But for some reason using > does not print anything to the output text file. Empty.
    Running curl without redirect do print out my IP.
    Hum......?
     
    Last edited: 31 Jul 2024
  3. wyx087

    wyx087 Multimodder

    Joined:
    15 Aug 2007
    Posts:
    12,068
    Likes Received:
    746
    Restored my alias by doing the following:

    Code:
    alias rdip='readip ; echo "-- ^ local - v VPN --" ; pct exec 201 /root/check_ip.sh ; sleep 1 ; tail -n 1 /mnt/ramdisk/pipe_out.txt '
    
    Inside the LXC, simply put an executable script containing the following:
    Code:
    curl -s icanhazip.com > /mnt/ramdisk/pipe_out.txt
    /mnt/ramdisk is mounted tmpfs on host, then passed through as mount point into LXC.
    In lxc config file:
    Code:
    mp1: /mnt/ramdisk,mp=/mnt/ramdisk
    Never figured out why curl wouldn't print into text file, probably due to some file permission error.
     
  4. RedFlames

    RedFlames ...is not a Belgian football team

    Joined:
    23 Apr 2009
    Posts:
    15,672
    Likes Received:
    3,150
    [​IMG]
     
    wyx087 likes this.

Share This Page