{"id":25977585,"url":"https://github.com/nylander/exercise_for_working_with_stderr_and_stdin","last_synced_at":"2026-05-12T19:03:22.974Z","repository":{"id":221000956,"uuid":"753171908","full_name":"nylander/Exercise_for_working_with_STDERR_and_STDIN","owner":"nylander","description":"Simple exercise for working with STDERR, STDIN, and transferring files from and to a server","archived":false,"fork":false,"pushed_at":"2024-02-05T16:07:49.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-02-06T17:05:41.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nylander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-05T15:57:15.000Z","updated_at":"2024-02-05T15:57:44.000Z","dependencies_parsed_at":"2024-02-05T17:05:36.758Z","dependency_job_id":"cf1cbaab-d2a4-4ff0-88e3-cfd70517c94b","html_url":"https://github.com/nylander/Exercise_for_working_with_STDERR_and_STDIN","commit_stats":null,"previous_names":["nylander/exercise_for_working_with_stderr_and_stdin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylander%2FExercise_for_working_with_STDERR_and_STDIN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylander%2FExercise_for_working_with_STDERR_and_STDIN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylander%2FExercise_for_working_with_STDERR_and_STDIN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylander%2FExercise_for_working_with_STDERR_and_STDIN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nylander","download_url":"https://codeload.github.com/nylander/Exercise_for_working_with_STDERR_and_STDIN/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241966989,"owners_count":20050324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-05T04:38:35.617Z","updated_at":"2026-05-12T19:03:17.908Z","avatar_url":"https://github.com/nylander.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exercise for learning STDERR and STDIN, and working on a remote server\n\n- Last modified: mån feb 05, 2024  05:06\n- Sign: Johan.Nylander\n- Please see the [Setup](#setup) in the end for installation and requirements.\n\n---\n\n## Task\n\nStart program [`prog`](prog) on remote server and handle output.\n\n## Background\n\nYou want to start a time-consuming analysis on a remote server, but you\ndo not have time so sit and wait for the process to finish, so you want\nto be able to logout and check in again later to fetch the results.\n\n## Outline of workflow\n\n1. Connect to server\n2. Create a new directory for the exercise\n3. Start the job\n4. Logout from the server (while keeping your program running)\n5. Login again\n6. Terminate (kill) the running process\n7. Create a compressed archive (`*.tgz`) containing the result\n8. Transfer the compressed archive to your local computer\n9. Uncompress the archive locally\n\n## Steps\n\n### 1. Use ssh to connect to BBB\n\nFirst, make sure you are connected to the local (course) WiFi network,\notherwise the server can't be found (see [Setup](#setup) below).\n\nThe way you connect with `ssh` is:\n\n    $ ssh usernameonserver@addresstoserver\n\nThe `addresstoserver` is the IP number or name of BBB. The\n`usernameonserver` is the user name you was given on the BBB server.\n\nYou will be asked if you really want to connect to this server, and then be\nasked for a password.  The password is the one associated with the\n`usernameonserver`.\n\nNote: If/when you want to disconnect from the remote server, type `exit`.\n\n### 2. Create a new directory for the exercise\n\nRemember `mkdir` command?\n\n### 3. Start the program (named `prog`) and handle the output\n\nYou want to make sure you save *the very important results* from `prog`.  You\nalso want to make sure you can logout while your program `prog` is running.\nHow can this be achieved? Just as with any (many) programs you use for the\nfirst time, this may require some trial-and-error (and/or reading the program\ndocumentation).\n\n**Hints:** Do you remember STDERR and STDOUT? Useful tools are the redirection\noperators (`\u003c`, `\u003e`, `2\u003e`, `\u003e\u003e`, `2\u003e\u003e`) and the use of `\u0026` to put processes in\nthe background.\n\nExamples:\n\n    # Redirect stdout to newfile. newfile will be created if it's not there, otherwise owerwritten.\n    $ cat infile \u003e newfile\n\n    # Redirect stdout and append to newfile. newfile will be created if it's not there.\n    $ cat infile \u003e\u003e newfile\n\n    # Redirect stdin\n    $ someprogram \u003c infile\n\n    # Redirect stderr. newfile will be created if it's not there, otherwise owerwritten.\n    $ cat infile 2\u003e newfile\n\n    # Redirection can be combined.\n    $ cat infile \u003e newfile1 2\u003e newfile2\n    $ someprogram \u003c infile \u003e newfile1 2\u003e newfile2\n\n    # Put process in the background (i.e., \"get the prompt back so we can logout\")\n    $ someprogram \u0026\n\n    # And all at once (very useful). Here, `someprogram` reads input from a file.\n    $ someprogram infile \u003e outfile 2\u003e logfile \u0026\n\n### 4. Make sure `prog` is running in the background (Step 3.), then logout from the server\n\nTo logout, type `exit`\n\n### 5. Log back in again, and check the progress of your job\n\nUseful tools: `ps`, `tail`, `top -c` (type `q` to exit `top`).\n\n### 6. Terminate (kill) your running job\n\nFirst you need to find the process ID of your job. This can be seen by using\n`ps` or `top` (press `q` to exit `top`).  Then you can kill the process by\nusing, e.g., `kill` or `killall`.  `kill` uses the process ID, and `killall`\nthe name of the program as argument.\n\nExamples:\n\n    $ kill 11296\n    $ killall prog\n\n### 7. Gather your very important results\n\nA good way to do this (and to get faster file transfer) is to use `tar`.\n\nRemember the `tar` syntax?\n\n### 8. Transfer the file(s) back to your computer!\n\nThis is done by using secure copy (`scp`).\n\nGeneral syntax:\n\n\\small\n\n    $ scp useronmachine1@machine1:/path/to/sourcefile useronmachine2@machine2:/path/to/destinationfile\n\n\\normalsize\n\nStart by making sure you know all the relevant information on paths, users,\nmachines etc.  The command can be issued from any computer, that is, in this\nexample you can issue the command in a terminal connected to the server, or in\na terminal connected on your local machine. Furthermore, you can take advantage\nof the fact that `scp` have some default settings, which allows you to use\nrelative paths etc.\n\n##### Example 1: fetching a remote file from server to your local computer (where you are typing the command):\n\n    $ scp useronremoteserver@remoteserver:/path/to/sourcefile .\n\n`useronremoteserver` might be `user01`, and `remoteserver` might be `10.0.0.1`.\nNote the period (`.`) in the end of the command. This stands for \"right here\"\nand is the current working directory, i.e., the directory from where the `scp`\ncommand is issued.\n\n##### Example 2: Copying a file from remote server (where you are typing the command) to your local computer:\n\n    $ scp sourcefile useronlocalcomputer@localcomputer:.\n\n`useronlocalcomputer` -- type `whoami` in a terminal on the local computer if\nyou don't remember who you are!\n\n`localcomputer` -- you can see the IP address of your local computer by typing\n`hostname -I`.\n\nNote the period (`.`) at the end of the command. This stands for \"right here\",\nand in the current context it will be the home directory of\n`useronlocalcomputer` on the local computer.\n\nAs a note, if you can make sure to have the same user name on local and remote\nservers, the `useronremoteserver@` part can be left out. Furthermore, if you\nset up your `ssh` connection with keys, then there is no prompting for\npasswords (see, e.g.,\n\u003chttp://yourtoolbox.blogspot.se/2012/08/ssh-connection-with-no-password.html\u003e)\n\n### 9. Uncompress locally\n\nRemember the arguments to `tar`?\n\n### 10. Extra: Now repeat all of this, but fetch the output from the progress printing!\n\n---\n\n## Setup\n\nThis exercise requires a server (BBB) where users can log in and start the\npre-installed program [`prog`](prog). The server should allow users to run\nprocesses in the background.  The first version of this exercise used the\nserver setup described here: \u003chttps://github.com/nylander/BBB\u003e.\n\nThe program [`prog`](prog) is written in Perl and requires `perl` (invoked by\n`/usr/bin/env perl`).\n\nTarget audience are beginners in using the command line for computing.\n\nLinux commands and operators used in this exercise: `cd`, `ls`, `ssh`, `mkdir`,\n`\u003c`, `\u003e`, `2\u003e`, `\u003e\u003e`, `2\u003e\u003e`, `\u0026`, `cat`, `exit`, `ps`, `tail`, `top`, `kill`,\n`killall`, `tar`, `scp`, `hostname`, `whoami`, `STDERR`, `STDOUT`, `Ctrl+c`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylander%2Fexercise_for_working_with_stderr_and_stdin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnylander%2Fexercise_for_working_with_stderr_and_stdin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylander%2Fexercise_for_working_with_stderr_and_stdin/lists"}