Send local files to remote
scp -r /Users/Jiachi/Desktop/RA_Prof.ChenNan/extracter.py zlab@nan.d2.comp.nus.edu.sg:/mnt/ssd2/home/zlab/users/Jiachi

Check this storm.cis.fordham.edu/~yli/documents/CISC2200Fall21/5_TransferFilesScpMac.pdf for more reference

Run Codes in the Background in Server

See SSH - Run Codes in the Background.

Q&A

  1. Will the CSV Output Appear Automatically After the Scripts Finish?

    • If each script is set up to save output directly to a .csv file (e.g., with pandas.to_csv("output.csv")), the files will be created automatically as long as the script completes successfully. You don’t need to do anything further, and the output files will be available on the server as soon as each script finishes.
    • If your scripts are instead printing output to the terminal, you won’t see that output directly in the .csv files. To ensure the output goes to .csv files, make sure each script is saving the data directly within the code.
  2. Will the Scripts Stop Running If You Lose Connection with the Server?

    • No, if you start each script within a screen session and then detach the session (using Ctrl+A D), they will continue to run in the background, even if you disconnect from the server.
    • screen is designed to keep sessions alive independently of your SSH connection, so you can log out without stopping the scripts.

In short, once you set up each screen session to run and detach them, your scripts will run to completion and save their .csv output files without needing further intervention. You can reconnect to the server anytime to check on the files or reattach to the sessions if needed.

Kill Screen

To stop all screen sessions that are running your scripts, you can follow these steps:

  1. List All Active Screen Sessions:

    • First, check all active screen sessions:

      screen -ls
  2. Terminate Each Session:

    • For each session you want to stop, use the following command to quit:

      screen -S session_name -X quit
    • Replace session_name with the name or ID shown in the screen -ls output, like race_full or race_last.

    • For example:

      screen -S race_full -X quit
      screen -S race_last -X quit
  3. Kill All Screen Sessions at Once (Optional):

    • If you want to terminate all screen sessions at once, use:

      screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
    • This command finds all detached sessions and kills them. Be careful, as this will stop all running screen processes.

After running these commands, all the screen sessions running your scripts will be stopped, and the scripts will no longer be running in the background.

Copy from File from Folder A to Folder B

cp example.txt ~/Documents