0

I want to run a python script in a tmux session on startup when launching my google cloud vm. I have searched around stack overflow and found this piece of code.

#! /bin/bash
sudo -H -u MyUser tmux new-session -d -s discord 'python3 MyFile.py'

I placed this in the meta data part of my vm where startup_scripts go but it doesn't launch when i start my vm. However when I run this code in the terminal after my vm has started it does exactly what I want it to do. What am I missing here?

  • Using the Compute Engine serial port to review the logs. Check if the command is being executed and if there is an error. – John Hanley Oct 06 '21 at 22:35

1 Answers1

0

After digging around for I while I found the problem. The command runs in the root directory so, before your piece of code, you have to add:

Add: cd home/username

Before your code.

ouflak
  • 2,458
  • 10
  • 44
  • 49