import asyncio
from mirage import MountMode, Workspace
from mirage.vfs.ssh import SSHConfig, SSHVFS
config = SSHConfig(
host="myserver",
username="deploy",
identity_file="~/.ssh/id_ed25519",
root="/var/log",
)
vfs = SSHVFS(config=config)
async def main():
ws = Workspace({"/logs": vfs}, mode=MountMode.READ)
# List remote directory
r = await ws.execute("ls /logs/")
print(await r.stdout_str())
# Read last 20 lines of a log
r = await ws.execute("tail -n 20 /logs/nginx/access.log")
print(await r.stdout_str())
# Search across log files
r = await ws.execute('grep "ERROR" /logs/app.log')
print(await r.stdout_str())
# Find large files
r = await ws.execute("find /logs/ -name '*.log'")
print(await r.stdout_str())
# File metadata
r = await ws.execute("stat /logs/app.log")
print(await r.stdout_str())
if __name__ == "__main__":
asyncio.run(main())