title: Reading from named pipe freezes when piping tshark output

text: I'm trying to implement a web prefetching system. The purpose of a system like this is to “predict” future requests and prefetch them.   The system builds a predictive model from web navigation logs (Squid access.log files). The model is a dependency graph, where a node representing URL A has an arc to a node representing URL B if URL B has been requested immediately after URL A.   Once the model is built, the system receives queries of URLs requested by users, and make “predictions” based on the graph. Predictions are resources (URLs) very likely to be requested in the future. So, based on predictions, the system prefetches these resources to store them in cache prior to users' requests. I'm using the following testing scenario:   - A process simulate multiple clients, requesting URLs in a file using libcurl. The process runs in a different PC from the prefetching system. PCs are connected directly via an ethernet cable   - Requests made by the client simulator are always the same URLs in the same relative time from the first request made. All requests are going to port 3128 (Prefetch PC Squid listen port) (port 80 DNAT to port 3128 in the client).   - The prefetching system runs in a CentOS 6.3 box, kernel 2.6.32-71.el6.i686, 2 core Intel Pentium 4 3.00GHz processor, 4 GB RAM.   - The prefetching system is one process with multiple threads. The main thread creates the predictive model and generates predictions based on queries. A “listener” thread reads URLs requested by users and prefetches predicted URLs using libcurl. “Listening” means reading from a named pipe (called url_fifo) URLs captured live on an interface using tshark:   `stdbuf -o0 tshark -i eth1 tcp port 3128 and "tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420" -T fields -e http.request.full_uri >> url_fifo`   - Each 10 minutes (1 cycle) the model is updated based on requests from the last cycle. The client tells the system when a cycle ends and so the model is updated. Once the model is updated, the system tells the client to start requesting URLs from the next cycle.  Here is the situation: Sometimes reading from the named pipe freezes. No URLs are read from the pipe even though tshark keeps capturing URLs and redirecting them to the named pipe. After an hour (or a couple of hours) all “buffered” URLs are read in less than 10 minutes. After that, reading from the pipe keeps going ok again. This situation doesn't happen always (50% of times freezes, 50% no). It seems that there is a buffering issue, since tshark keeps capturing URLs and all requests are correctly logged in Squid's access.log. In the beginning, I ran tshark with the `-l` option, so that its output becomes line buffered. Then I started using `stdbuf -o0` (no buffering). Anyway the situation still happens. In the system code, I also tried opening and reading the named pipe as a stream (`FILE *`) and set the stream as no buffered or line buffered (using `setvbuf()` function). The situation still happened.   In some cycles requests are faster than in other cycles. Anyway, it doesn't seems to be a fast producer slow consumer issue, since in many repetitions of the test all URLs are correctly read and processed without any freezes. Is there something am I missing related to named pipes and buffering? I'd really appreciate some guidance. Assume networking (interfaces, routing, iptables, squid) is ok. I've not had any issues related to it. Code (assume necessary header files are included): functions.c               #define BUFLEN 512     #define QUEUE_LEN 64     #define THREADS_LEN 2               pthread_mutex_t model_lock;     pthread_cond_t model_cond, listen_cond;     pthread_t queries_thread, listen_thread;     short int model_is_updating, model_can_update, program_shutdown;          /* Program execution statistics */     Status * program_status;          /* Thread pool */     threadpool_t *pool;                    /* program execution */     int     run(void)     {         Graph_Adj_List * gr = NULL; /* Graph as an adjacency list */         char ** reports = NULL;         unsigned report_counter = 0;              /* Init program status */         program_status = status_init();              /* Load list of custom web navigation reports to be used to build the initial          * version of the predictive model */         reports = file_load_reports(program_config.reports_file);         if (!reports)             return 0;              /* Init mutex and cond */         pthread_mutex_init(&model_lock, NULL);         pthread_cond_init(&model_cond, NULL);         pthread_cond_init(&listen_cond, NULL);              /* Lock */         pthread_mutex_lock (&model_lock);              /* Start first cycle */         status_start_cycle(program_status);              /* Create initial version of the predictive model */         gr = create_model_from_files(reports, &report_counter, program_config.reports_limit);         if (!gr)         {             /* Unlock */             pthread_mutex_unlock (&model_lock);             return 0;         }              /* Unlock */         pthread_mutex_unlock (&model_lock);              /* Start threads */         if (pthread_create(&queries_thread, NULL, fifo_predictions_threaded, (void *)gr) ||                 pthread_create(&listen_thread, NULL, listen_end_of_cycle, NULL))             program_shutdown = 1;              /* main loop */         while(!program_shutdown)         {             /* lock */             pthread_mutex_lock (&model_lock);                  /* wait for clients' announcement of the end of requests from current cycle */             while (!model_can_update)                 pthread_cond_wait(&model_cond, &model_lock);                  /* set updating flag */             model_is_updating = 1;                  /* Update predictive model, based on Squid's access.log from (about to finish)              * current cycle */             adj_list_update_access(gr, program_config.access_file);                  /* Save statistics related to the current cycle and finish it */             status_finish_cycle(program_status);                  /* Check if last custom report has been read */             if (!reports[report_counter])             {                 program_shutdown = 1;                 pthread_mutex_unlock (&model_lock);                 break;             }                  /* Start a new cycle */             status_start_cycle(program_status);                  /* Read a new custom report and update the predictive model */             update_model(gr, reports[report_counter]);                  report_counter++;                  /* Updating is done */             model_is_updating = 0;                  /* Model can't be updated until client announces the end of the cycle              * that has just started */             model_can_update = 0;                  /* Tell client to start sending requests from the new cycle */             if  (!signal_start_cycle())             {                 program_shutdown = 1;                 pthread_mutex_unlock (&model_lock);                 break;             }                  /* Signal listener thread that a new cycle has begin */             pthread_cond_signal(&listen_cond);                  /* Unlock */             pthread_mutex_unlock (&model_lock);         }              /* Finish threads */         pthread_cancel(listen_thread);         pthread_cancel(queries_thread);         pthread_join(listen_thread, NULL);         pthread_join(queries_thread, NULL);              /* Free memory */         adj_list_free_all2(&gr);         file_reports_free_all(&reports);         pthread_cond_destroy(&model_cond);         pthread_cond_destroy(&listen_cond);         pthread_mutex_destroy(&model_lock);         status_free(&program_status);              return 1;     }               void *     fifo_predictions_threaded(void * data)     {         Graph_Adj_List * gr = (Graph_Adj_List *) data;              /* Set thread cancel type */         pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);              while (!program_shutdown)         {             pthread_mutex_lock(&model_lock);                  /* Pause reading from named pipe while the model is being updated */             while(model_is_updating)                 pthread_cond_wait(&listen_cond, &model_lock);                  pthread_mutex_unlock(&model_lock);                  /* Read URLs from named pipe */             fifo_predictions(gr, program_config.fifo);         }              pthread_exit(NULL);              return NULL;     }               int     fifo_predictions(Graph_Adj_List * gr, const u8 * fifo)     {         u8 cad[BUFLEN] = { '\0' };         u8 * ini = NULL, * fin = NULL, * fullurl = NULL;         int i, fifo_descriptor, read_urls = 0, fullurl_len = 0, incomplete_url = 1;         FILE * fifo_file = NULL;              /* Open fifo in blocking mode */         fifo_descriptor = open(CHAR_CAST fifo, O_RDONLY);         /* Open fifo as a stream */         //  fifo_file = fopen(fifo, "r");          //  if (!fifo_file)         if (fifo_descriptor == -1)             return 0;              /* If fifo is opened as a stream, set it line buffered */     //  setlinebuf(fifo_file);              do         {             if ((i = read(fifo_descriptor, cad, BUFLEN - 1)) == -1)     //      if ( fgets(cad, BUFLEN-1, fifo_file) == NULL)                 ERROR(__FILE__, __FUNCTION__, __LINE__, "Fifo read error");             else             {     //          i = strlen(cad);                      cad[i] = '\0';                 read_urls = 0;                      if (i > 0)                 {                     int j = 0;                     for (j = 0, ini = cad, fin = NULL ; cad[j] != '\0'; j++)                     {                         if (cad[j] == '\n')                         {                             /* Save URL */                             fin = &cad[j];                             ini = (*ini == '\n' ? ini + 1 : ini);                                  /* Check if string is a continuation of the previously read URL */                             read_urls = fin - ini;                             read_urls = read_urls >= 0 ? read_urls : 0;                                  /* Save URL in fullurl string */                             fullurl = realloc(fullurl, fullurl_len + read_urls + 1);                             memcpy(&fullurl[fullurl_len], ini, read_urls);                             fullurl[fullurl_len + read_urls] = '\0';                                  ini = fin;                             incomplete_url = fullurl_len = 0;                                  /* Ask the model for predictions and fetch them */                             fetch_url_predictions2(gr, fullurl);                                  u8_free(&fullurl);                              } else                             incomplete_url = 1;                     }                          if (incomplete_url)                     {                         ini = (*ini == '\n' ? ini + 1 : ini);                         read_urls = &cad[j] - ini;                         read_urls = read_urls >= 0 ? read_urls : 0;                         fullurl = realloc(fullurl, fullurl_len + read_urls);                         memcpy(&fullurl[fullurl_len], ini, read_urls);                         fullurl_len += read_urls;                     }                      }             }         } while (i > 0);              close(fifo_descriptor);     //  fclose (fifo_file);              return 1;     }               int     fetch_url_predictions2(Graph_Adj_List * gr, u8 * in_url)     {         String * string_url = NULL;         Headnode * head = NULL;         LinkedList * list = NULL;         LinkedListElem * elem = NULL;              /* Use custom string type */         string_url = string_create_no_len(in_url);         if (!string_url)             return 0;              pthread_mutex_lock(&model_lock);              /* Get URL node */         head = adj_list_get_node(gr, string_url);              if (head)         {             /* Get predictions (URLs) as a linked list */             list = adj_list_predictions_to_list(head);             if (!list)             {                 string_free_all(&string_url);                 return 0;             }                  pthread_mutex_unlock(&model_lock);                  /* Callback fetches URLs */             list->callback = &curl_callback_void;                  if (!pool)                 pool = threadpool_create(THREADS_LEN, QUEUE_LEN, 0);                  /* Load URLs to be fetched to threadpool's task queue */             for (elem = list->first; elem; elem = elem->next)             {                 CallbackArg arg;                 arg.data = arg.copy(elem->data);                      threadpool_add_copy_arg(pool, list->callback, &arg, 1, sizeof(arg), 0);             }                  linked_list_free_all(&list);         }              pthread_mutex_unlock(&model_lock);              string_free_all(&string_url);              return 1;     }      fetch.c               void     curl_callback_void(void * data)     {         CallbackArg * arg = (CallbackArg *) data;         char * url = (char *) arg->data;              fetch_url(url);     }               static size_t     write_data(void *buffer, size_t size, size_t nmemb, void *userp)     {         return size * nmemb;     }               int     fetch_url(char * url)     {         CURL *curl;         CURLcode res;         struct timeval time;         char * time_string = NULL;              curl = curl_easy_init();         if (curl)         {             curl_easy_setopt(curl, CURLOPT_URL, url);             curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);             curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);             curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);             curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);             curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);             curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);             curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);             curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);                  /* Perform the request, res will get the return code */             res = curl_easy_perform(curl);                  gettimeofday(&time, NULL);             time_string = timeval_to_str(&time);                  /* Check for errors */             if (res != CURLE_OK)             {                 fprintf(stderr, "\ntime %s curl_easy_perform() (url %s) failed: %s\n",                         time_string, url, curl_easy_strerror(res));             }             else             {                 fprintf(stderr, "\ntime %s curl_easy_perform() (url %s) fetched ok\n",                         time_string, url);             }             fflush(stderr);                  free (time_string);                  curl_easy_cleanup(curl);         }              return 0;     }      network.c               /*      * Code based on Beej's Networking Guide      */          #define MSG_LEN     5     #define QUEUE_SIZE  5               extern pthread_mutex_t model_lock;     extern pthread_cond_t model_cond;     extern short int model_can_update, program_shutdown;     extern Config program_config;               // get sockaddr, IPv4 or IPv6:     static void *     get_in_addr(struct sockaddr *sa) {         if (sa->sa_family == AF_INET) {             return &(((struct sockaddr_in*) sa)->sin_addr);         }              return &(((struct sockaddr_in6*) sa)->sin6_addr);     }               void *     listen_end_of_cycle(void * data)     {         int sockfd, new_fd;  // listen on sock_fd, new connection on new_fd         struct addrinfo hints, *servinfo, *p;         struct sockaddr_storage their_addr; // connector's address information         socklen_t sin_size;         int yes = 1;         char s[INET_ADDRSTRLEN], msg[MSG_LEN], *str = NULL;         int rv;         int read_bytes;         struct timeval actual_time;              /* Set thread cancel type */         pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL );              memset(&hints, 0, sizeof hints);         hints.ai_family = AF_INET;         hints.ai_socktype = SOCK_STREAM;         hints.ai_flags = AI_PASSIVE; // use my IP              if ((rv = getaddrinfo(NULL, program_config.listen_port, &hints, &servinfo))                 != 0) {             fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));             return "error";         }              // loop through all the results and bind to the first we can         for (p = servinfo; p != NULL ; p = p->ai_next) {             if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol))                     == -1) {                 perror("server: socket");                 continue;             }                  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))                     == -1) {                 perror("setsockopt");                 return "error";             }                  if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {                 close(sockfd);                 perror("server: bind");                 continue;             }                  break;         }              if (p == NULL ) {             fprintf(stderr, "server: failed to bind\n");             return "error";         }              freeaddrinfo(servinfo); // all done with this structure              if (listen(sockfd, QUEUE_SIZE) == -1) {             perror("listen");             return "error";         }              while (!program_shutdown)         {             sin_size = sizeof their_addr;             new_fd = accept(sockfd, (struct sockaddr *) &their_addr, &sin_size);             if (new_fd == -1) {                 perror("accept");                 continue;             }                  inet_ntop(their_addr.ss_family,                     get_in_addr((struct sockaddr *) &their_addr), s, sizeof s);                  if ((read_bytes = recv(new_fd, msg, MSG_LEN - 1, 0)) == -1) {                 perror("recv");                 continue;             }                  close(new_fd);                  msg[read_bytes] = '\0';                  /* Check received message */             if (strcmp(msg, "DONE")) {                 perror("Not valid message");                 continue;             }                  printf("\ngot \"DONE\" from %s\n", s);             fflush(stdout);                  /* Lock */             pthread_mutex_lock(&model_lock);                  /* Flag used by main thread to allow model update */             model_can_update = 1;                  /* Signal model can be updated */             pthread_cond_signal(&model_cond);                  /* Unlock */             pthread_mutex_unlock(&model_lock);         }              close(sockfd);              pthread_exit(NULL);              return "ok";     }               int signal_start_cycle(void) {         int sockfd;         struct addrinfo hints, *servinfo, *p;         int rv;         char s[INET6_ADDRSTRLEN], *str = NULL;         struct timeval actual_time, aux_time;         struct timeval connect_timeout = { 15, 0 }, max_connect_time = { 0, 0 };         short int connected = 0;              memset(&hints, 0, sizeof hints);         hints.ai_family = AF_INET;         hints.ai_socktype = SOCK_STREAM;              if ((rv = getaddrinfo(program_config.client_ip, program_config.client_port,                 &hints, &servinfo)) != 0) {             fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));             return 0;         }              gettimeofday(&aux_time, NULL);         timeval_add(aux_time, connect_timeout, &max_connect_time);              /* Try several times to connect to the  remote side */         do {                   // loop through all the results and connect to the first we can             for (p = servinfo; p != NULL ; p = p->ai_next) {                 if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol))                         == -1) {                     perror("client: socket");                     continue;                 }                      gettimeofday(&actual_time, NULL )                 printf("\ntrying to connect %s\n", program_config.client_ip);                 fflush(stdout);                      if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {                     close(sockfd);                     perror("client: connect");                     continue;                 }                      connected = 1;                 break;             }              } while (!connected && !timeval_greater_than(actual_time, max_connect_time));              if (p == NULL ) {             fprintf(stderr, "client: failed to connect\n");             return 0;         }              inet_ntop(p->ai_family, get_in_addr((struct sockaddr *) p->ai_addr), s,                 sizeof s);              printf("\nMAIN THREAD: connecting to %s\n", s);         fflush(stdout);              freeaddrinfo(servinfo); // all done with this structure              if (send(sockfd, "DONE", 4, 0) == -1)         {             perror("send");             return 0;         }              printf("\nsent \"DONE\" to %s\n", s);         fflush(stdout);              close(sockfd);              return 1;     }


title: How to find executable filetypes?

text: I want to find file types that are executable from the kernel's point of view. As far as I know all the executable files on Linux are ELF files. Thus I tried the following: `find * | file | grep ELF` However that doesn't work; does anybody have other ideas?


title: Extract file from completely disconnected machine, possibly via Kernel messages

text: I have a VPS running inside an OpenStack cloud that has more or less crashed completely - the provider hasn't been able to get any kind of networking on it for over 2 days, seems completely broken on their end. The server itself has already been migrated elsewhere, no harm done there, but there is a single text file left on the machine that I need. Only connection I have to the server is an HTML5 Canvas based web interface. Since it's a canvas, copy/paste isn't possible. I can't get any networking going on the machine. The file itself is a 2Kb private key, and running OCR on screenshots gets thoroughly confused between 0 and O, 1 and I, and other things because it has no context. Obviously typing over a square block of nearly 2000 characters of which every typo means the result isn't a valid key is not a really viable or attractive option. Losing the key means having to purchase a new $200 certificate. The only thing I have left is the Console Output Log in the OpenStack GUI, which shows everything that's being logged to the console at kernel level, in plaintext. If I can dump the file to there I can copy/paste it out. Now I have tried everything I know, from `logger -s` to `cat my.key > /dev/console`, but it's not showing up there. Anyone have an idea how to do this, or another option to retrieve the file?


title: Lightweight browser for linux

text: Is there a lightweight, fast browser (for old hardware) for linux which has the following features:   * supports tags for bookmarks and has a tag search function   * supports (possibly via plugins) most modern web media (e.g. youtube videos ...)   * has an ad-blocker (like adblock plus in firefox)   * incremental search   * should be stable   * actively maintained in particular for security updates Not a strict requirement but nice to have:   * import firefox bookmarks   * undo closed tabs   * something like downthemall in firefox   * incremental link-search which supports following links via keyboard


title: How to view traffic over a forwarded ssh port?

text: It is possible to setup an SSH port forward where the ssh client prints out the traffic exchanged over the ssh port to the screen or a file. I am trying to debug a problem and want to see what is being sent between a java process running on my local machine and a remote process running on Solaris. I am using the port forwarding via ssh so that i can step through the java program. Normally I would have to copy the .java files to the Solaris machine, build them and run and it is not very productive way to debug, thus the port forwarding. The client and server as using IIOP protocol so I can't use an http proxy to monitor the traffic.


title: Finding sparse files?

text: Is there a straightforward way to find all the sparse files on my system, or in a particular directory tree? If it's relevant, I'm using `zsh` on Ubuntu 12.04, although a more generic Unix-y answer for bash/sh, for example, would be fine. **Edit** : to clarify, I'm looking to search for sparse files, not check the sparseness status of a single one.


title: Vim - buffer names in the cmd line area

text: When I edit files with vim there is always this in the cmd line area,under the status line,all buffers' names(image : ![http://ompldr.org/vOHZtdg](http://i.stack.imgur.com/C15cq.png)) Is there any way I can remove it?


title: Why don't these cron jobs run?

text: Here is my crontab:               # rsnapshot jobs     0 9-21 * * *         /usr/bin/rsnapshot -c /home/kaiyin/.rsnapshot.conf hourly     52 22 * * *          /usr/bin/rsnapshot -c /home/kaiyin/.rsnapshot.conf daily     42 22 * * 6          /usr/bin/rsnapshot -c /home/kaiyin/.rsnapshot.conf weekly     32 22 1 * *          /usr/bin/rsnapshot -c /home/kaiyin/.rsnapshot.conf monthly          * * * * * /bin/echo hi >> /tmp/testlog      The last one runs ok, but the rsnapshot ones will not run, why?


title: What is a better way to deal with server disconnects of sshfs mounts?

text: I have several directories mounted through _sshfs_. I sometimes get disconnects from the server (not configurable by me). I usually mount the directories like this               sshfs user@server.example.com:/home/user /mnt/example      When a server disconnects, the sshfs subsystem doesn't _umount / free_ the directory but instead locks it inaccessible. The mount is still visible when typing `mount`. When I type               ls /mnt/example      the process gets locked (also `Ctrl`+`c` doesn't help). I therefore do               sudo umount -l /mnt/example     # find pid of corresponding process:     ps aux | grep example.com     kill -9 <pid of locked sshfs process>      Is there a better way to deal with this? Obviously _sshfs_ should do the _umount_ and clean up... Ideally it would reconnect automatically.


title: GNU screen: move between regions

text: I've started splitting window in GNU screen into different regions - rather than switching between windows. Anyway, having split a window into 4 regions (2x2) it takes 3 `C-a <Tab>` to return focus to the original region. That is quite cumbersome... Are there other keybindings to _move up, down, left, right_ between regions? I can't understand this: hitting `C-a t` gives me time, does not switch to top win. Should I change keybindings?


title: Pipeline with grep and find prints numbers infront of result

text: Am using the following "find" command to extract some files,               find /lag/cnnf/ -maxdepth 3 -newer ./start ! -newer ./end | grep -nri abc | egrep '([^0-9]45[^0-9])' | grep -nri "db.tar.gz" >> sample.txt      My output in sample.txt is               5:175:/lag/cnnf/abc/45/r-01.bac.db.tar.gz     20:190:/lag/cnnf/abc/45/r-01.bac.db.tar.gz      what should i do to get only,               /lag/cnnf/abc/45/r-01.bac.db.tar.gz     /lag/cnnf/abc/45/r-01.bac.db.tar.gz      without the random numbers in front of it and what those numbers actually mean.


title: Customize Top Panel / Global Menu / Super-Wingpanel in Elementary OS Luna

text: How on ElementaryOS change Wingpanel on **Top Panel** / **Global Menu** / **Super-Wingpanel** like OS X ? ![enter image description here](http://i.stack.imgur.com/PlYrO.png)


title: Setting system/hardware clock under Debian

text: I have installed a system with a London timezone, instead of using Central European Time. The problem is, that hwclock says the time is 11:00, date says the time is 11:00. I have changed the timezone with tzselect, that also reads the correct value (Prague). And the logs still show that the time is 10:00. What I'm missing?


title: Gives access to root user for a period of time

text: I want to know if it's possible to give access to root user for one week or a month, for example. It's possible to increase the period of time before the defined period ends? Is it possible to give access without time limitation, forever?


title: Antergos installer says I have no /boot partition

text: When attempting to install Antergos(Arch-based Linux distro) I am told that it cannot install as I have not specified a /boot partition, when I appear to have done just that. I have attached a picture of the problem (sorry for the terrible quality.) ![Picture of described problem.](http://i.stack.imgur.com/A3ZN4.jpg)


title: How to fake the source-port of a TCP packet?

text: Is there an easy way (or is it possible at all) to rewrite a TCP packet as it leaves the machine?   For example if I run               telnet binfalse.de 22      it will search for an unused port to leave the machine. In this case it's `46576`:               root@srv % lsof -i -P -n | grep telnet     telnet    10150   user    3u  IPv4 1159425      0t0  TCP 1.2.3.4:46576->87.118.88.39:22 (ESTABLISHED)      But now I want to rewrite these packets to let the server think the requests came from port `1337`, or somewhat like this. Of course I know that I don't have to expect an answer in my `telnet` session. **EDIT:**   Of course on `1337` another program is listening, so telling `telnet` to speak through `1337` is no option...


title: Run mpirun and ssh-add remotely on the same session

text: I am developing a program that is running on multiple machines using MPI. I have machines on Amazon EC2 where I can start _mpirun_ from one of them (the master). Everything works as I expect if I ssh to the master machine, then trigger `ssh-agent` and then `ssh-add my_rsa_key`. What I want to do, is to be able to have a script on my local machine where I trigger the `mpirun` on the master remotely with `ssh`, the problem is that I get `Permission denied (Public key)` because `ssh-add` is not receiving requests over that session (I suppose). Here is a very basic draft of the deploy script I am trying right now.               #!/bin/bash          MACHINES_LIST="M1     M2"               echo $MACHINES_LIST | tr " " "\n" | while read fn; do         echo "$fn"              echo "deploying and compiling to : $fn ..."         scp -i key "sample.c" user@$fn:/home/user         ssh $fn 'mpicc sample.c -o sample' &          done          echo "uploading lists of hosts to master M"     scp -i key .hosts user@M:/home/user          echo "starting mpirun on master M"          ##### Here mpirun needs to execute after ssh-add     ssh M 'exec ssh-agent bash;ssh-add my_rsa_key;mpirun --hostfile .hosts -np 10 sample'      Is there a way to make `mpirun` execute (remotely) within a session where `ssh-add` is running?


title: What are the differences between split and rar?

text: I am used to raring files -- but I am looking for something faster. I see that there is a "split" command. How does this command compare to `rar`? What is are the differences between `split` and `rar`?


title: Output of command not in stderr nor stdout

text: I've stumbled on this issue, so I'm wondering how is this possible? Standard run of command:               # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14     info from server: "Processed 0 Failed 1 Total 1 Seconds spent 0.000017"     sent: 1; skipped: 0; total: 1 OK, lets try to get the first line only:               # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 | head -1     sent: 1; skipped: 0; total: 1 What about standard head?               # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 | head      sent: 1; skipped: 0; total: 1 Inverse grep? sed? tee?!?!?!!?               # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 | grep -v pero     sent: 1; skipped: 0; total: 1          # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 | sed 's/foo/bar/'     sent: 1; skipped: 0; total: 1          # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 | tee     sent: 1; skipped: 0; total: 1 stderr to stdout?               # zabbix_sender -c zabbix_agentd.conf -k mmysql.QCInserts -o 14 2>&1 | tee     sent: 1; skipped: 0; total: 1 I'm really puzzled...


title: scp recursively directories on SunOS

text: I have encountered a small issue with SCP (and also rsync). I need to copy certain files from server A (running SunOS 5.8) to server B (running SunOS 5.10). First, I get the list of files (several hundred) via ssh and find               FILES=`ssh user@remote find ./ -name "*.sh" -o -name "*.cbs" -print`     scp -r user@remote:"$FILES" /u01/appl/somedir/       My problem is, I want to copy files with relative paths, e.g. `product/11/ora/clean.sh` creating also the directory structure (in result having `/u01/appl/somedir/product/11/ora/clean.sh`). Currently I am only able to download the file and no directories are created. As you can see I used `-r` flag in scp.


title: What has happened to the file when I entered "mv file.txt ../"?

text: I wanted to move 'file.txt' one folder up, but instead of `mv file.txt ../file.txt` I entered `mv file.txt ../`. Now the file is gone and I didn't get any error message. So it seems ~~the~~ some action was done successfully. But what happened here? I have backups, so at least that's no problem. But I'd like to understand what I did and if I changed anything or if this file magically disappeared.


title: apt-get has unmet dependencies, but apt-get -f install doesn't solve problem

text: I've tried to install emacs on Ubuntu server 64bit 11.04, but it's complaining about emacs23-common. If I do:               sudo apt-get -f install      I still see the same problem:               Errors were encountered while processing:      /var/cache/apt/archives/emacs23-common_23.2+1-7ubuntu2_all.deb     E: Sub-process /usr/bin/dpkg returned an error code (1)      How can I solve this situation?


title: Finding the right diplay driver for arch installation on a virtual box on Lenovo edge13''

text: I'm checking arch on a virtualbox (running on ubuntu) before I install it on my machine. I have followed the wiki up until the display driver section. lspci gives: > VGA compatible controller: InnoTek Systemberatung GmbH Virtual Graphics > Adapter I assume this is some sort of virtualbox compatible layer, is there a way to by pass it and test my real display driver (intel of some kind) on the virtual box?


title: How do I authenticate to a wireless provider's "open" network without using a browser?

text: This sort of a setup seems to be common in shopping malls and airports. In Western Canada Shaw provides such a service and calls it "Shaw Open". I'm pretty sure other locales have similar services from providers such as T-Mobile, etc. From something such as a cell phone it's not very complicated to do. No authentication is necessary to connect to the wifi hotspot as it is "open" for public access. But my cell phone won't connect to websites or remote services via apps **until I use my browser and sign in to a particular webpage provided by the ISP**. My question simply stated is: **How do I automate the authentication step from a device that doesn't typically have a traditional browser?** I have, in my particular case, a raspberry Pi configured with software that I want to use at trade shows etc. Theses locations have the same sort of "open" hotspots. The Raspi is meant to be self contained. It just does its business and talks to a website. But this outbound connection is blocked by the ISPs "open" connection because I haven't, nor can I complete the browser part of the process. Assuming I have credentials to do this on a particular provider's network, **how can I automate that part of the process without requiring me to open a terminal session to the Pi?** What kind of technology is even used here, that I can search for?


title: copy+paste between linux desktop and vmware player?

text: How can I copy+paste text between my linux desktop (GNOME Ubuntu 11.04) and the open vmplayer window running an ubuntu 64bit server terminal?


title: How to access network without NetworkManager in Fedora 15?

text: I am running Fedora 15 on VirtualBox 4 and I am failing to reach the internet:               $ ping 8.8.8.8     connect: Network is unreachable      Firefox also refuses, telling me "Server not found". Running `sudo service network restart` and restarting the VM didn't help.


title: Should my /usr/local/bin be 700 permissions?

text: I just installed npm and node.js, and I couldn't access `npm`. And I'm like "why?" and my OS is like "because /usr/local/bin is at 700 permissions" and I'm like "should it really be that way?" /usr/local is supposed to be .. the local user's bin folder? Then why does it require root access? It is filled with GAE stuff. Maybe Google App Engine changed it, I don't know.


title: mount options for bindmount

text: Due to some complex requirements, I had to put the following two lines in `/etc/fstab`:               /dev/xvdg1        /srv/storage  ext4  $OPTIONS1      0 2     /srv/storage/dir  /var/opt/dir  none  bind,$OPTIONS2 0 0      Now my question is: Do I have to re-list all mount options $OPTIONS1 in $OPTIONS2, or will the second line (the bindmount line) inherit the options of $OPTIONS1? FYI, here is the actual options used in $OPTIONS1:               rw,auto,async,noatime,nodiratime,barrier=0,delalloc      * * * **ETA** : actually I use `UUID=...` instead of `/dev/xvdg1`, but that's beside the point.


title: Aptitude - uninstalling autoinstalled packages that are recommended by other packages

text: I am running a Debian Wheezy install on a system where space is tight. Hence, I've turned off the "Automatically install recommended packages" option. The problem occurs if I install a package which results in a bunch of automatic dependencies. When I then remove that package, aptitude does not remove many of the automatically installed packages, for the reason that they are recommended by other packages. For instance, I installed pybliographer and was required to install almost 45 MB of packages. When I enter `aptitude remove pybliographer` a few hours later, I'm told that 3 MB will be freed. Trying `aptitude why` on a few random packages that were earlier installed - e.g. libgnomeui-0 - shows that they are recommended by some other package, but not depended on by any. The Debian documentation on "managing automatically installed packages" mentions that one can set `Apt::AutoRemove::SuggestsImportant` to false so that packages are not retained just because they are suggested by another package. But there is no reference to an option to do this for recommended packages - that page states that packages "will be removed when there is no path via Depends, PreDepends, or **Recommends** to them from a manually installed package." Is there no way this behaviour can be changed?


title: Seamless mode in XEN?

text: Is there a seamless mode for XEN like the solution for VirtualBox? UPDATE: under e.g.: having Ubuntu 11.04 as dom0. With seamless mode I mean to integrate the guest vm's window[s] to the host's GUI.


title: Network fail on FreeBSD: Ping to router fails, but router believes computer is connected

text: I have a TP-Link TL-WN851N wireless adapter, which is based on an Atheros device. When I attempt to connect to my WPA2 wireless network, `ifconfig wlan0` tells me that the connection is 'associated'. My computer also shows up as connected in the list on the router. However, I can not ping anything, even the router itself. On the same system, running Linux, there are no connection problems, and running Windows, there are occasional dropped connections, but no failure to reconnect. DHCP is noticeably slow on both of these however. After doing some debugging with people on the #freebsd channel on Freenode, I have found the following:   * `arp -an` shows up no routes.   * If I attempt to get an IP address from DHCP, it fails. On the FreeBSD system, it shows DHCPDISCOVER, then gives an error about no DHCPOFFER. According to my router's web interface, it believes it has given the computer an IP address after this.


title: Find a string only in a specific file inside subdirectories

text: Let's say I need to find the function `GetTypes()` in all C# source file (`.cs`) the directories/subdirectories. I used `grep -rn GetTypes *.cs`, but I got an error with `grep: *.cs: No such file or directory`. I had to use `grep -rn GetTypes *`, but in this case it shows all the files not `*.cs` only. What command do I need to use to find the string only in `.cs` files?


title: Why would vim return non-zero exit code if I exit immediately after opening?

text: I'm running into a bit of a strange problem w/ `vim` on Snow Leopard: I get a non-zero exit code from simply running `vim` and then quitting.               $ vim     # exit immediately using :q     $ echo $?     1      However, if I use the full path to `vim`, I don't see this behavior               $ /usr/bin/vim     # exit immediately using :q     $ echo $?     0      At first I thought `vim` was coming from somewhere earlier in my path, but:               $ which vim     /usr/bin/vim      So I'm at a loss. What could be causing this? UPDATE: This problem has magically resolved itself, which makes me highly suspicious. My current best theory is that I had a problem with my `.vimrc` or a plugin that I fixed accidentally while tweaking my setup in some other way. If I can track down exactly what I did to fix it, I will definitely update with that info. Thanks for the answers.


title: Sending some input into a process, then resuming input from command line

text: I have an interactive terminal program, that accepts stdin (telnet for example). I want to send it some input before interacting with it, like this:               echo "Hello" | telnet somewhere 123      But that only sends in `Hello` and kills telnet afterwards. How can I keep telnet alive and route input to it?


title: Read and process a string, char by char, yet allow user to simple line edit the input

text: I want to incrementally read a line of input from the terminal, and allow the user some basic line editing functionality; INS, DEL, RIGHT, LEFT HOME, END, BACKSPACE Each time the string is modified, I want to process it, to do an incremental regex search of a text file. These edit-keys, and others, generate multiple input characters which   make it rather difficult to interpret the input, eg C-Left generates 6 characters. Is there a simple way to achieve this char-by-char editable input?   I'm especialy interested in knowing how to do this in bash, because the rest of the processing will be bash.. Other suggestions are welcome too.. Here is how I started out, but it gets a bit out of hand with such a potential variety of control codes ..               #!/bin/bash     IFS=$'\n'      while true ;do       read -n 1 c       ((${#c}==0)) && break # Exit the loop. Input length is 0                               # ie. The user has pressed Enter       echo "xx=$(echo -n "$c"|xxd -p)="       # 1b 5b 32 7e  "INS"       # 1b 5b 33 7e  "DEL"       # 1b 5b 43     "RIGHT"       # 1b 5b 44     "LEFT"       # 1b 5b 46     "END"       # 1b 5b 48     "HOME"       # 7f           "BACKSPACE"     done


title: Screen corruption after hibernate — Is there another way to refresh the X11 display?

text: When I restore from hibernate the screen is often corrupted. I suspect the graphics memory is not being saved. Suspend-to-ram works fine. It also looks like the font-cache is corrupted, as all letters are corrupted consistently. **Logging out and back in again fixes it** , but I don't want to have to do that. I have been logging-out then hibernating, but this is more effort and eliminates most of the benefit of hibernate. **Is there another way to refresh the X11 display?** The `Ctrl`+`Alt`+`F1`… does not work. It switches terminal but does not redraw anything: It just shows the old corrupted screen. I am using Debian 6.


title: Batch copying/moving files in unix?

text: Is there a way to batch copy/move files in unix? I thought it might be an option for `cp/mv` but I can't find any way to do it.


title: Ignore Symlinks when Extracting Tarball

text: I have a relatively simple question that I cannot seem to find the answer for. I am attempting to extract a tarball (*.tgz, to be exact) and receiving terminal errors on extracted symlinks. Unfortunately, I cannot simply recreate the archive as this is a legacy archive for a system that no longer exists which was created before I was even out of high school (gotta love working for a big company). I have consulted the almighty Google; however all I can seem to find is information for excluding / following symlinks at _creation_ time. The exact error I am receiving is something of a misnomer (error: read-only filesystem) and comes from the fact that a very large portion of the data payload is contained within numerous squash / cram / loop filesystems. The symlinks are referencing data within them which, obviously, cannot be mounted due to errors while extracting said tarball. Chicken; meet egg. So, in short: **How can I extract a *.tgz archive to completion while either ignoring symlinks or ignoring resultant symlink errors?** For reference:               $ tar --version     tar (GNU tar) 1.26     Copyright (C) 2011 Free Software Foundation, Inc.     License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.     This is free software: you are free to change and redistribute it.     There is NO WARRANTY, to the extent permitted by law.          Written by John Gilmore and Jay Fenlason.     $ uname -a     Linux localhost.localdomain 3.7.9-205.fc18.x86_64 #1 SMP Sun Feb 24 20:10:02 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


title: How to Save X Session -- ArchLinux+Openbox

text: I use Arch Linux and Openbox. How can I save the state of my current openbox/X session and later restart them? The scenario is like this: I've several browsers windows open, terminals, file managers, etc., and for some reason at any moment I may need to _restart_ the computer. I would like to restore the set of windows I've previously using before the restart. Is it possible? How can I do it?


title: SOCKS proxy without ssh command

text: Currently I create a ssh tunnel using: `ssh user@server -D 1234` to use SOCKS proxy. How do I configure server so I can directly connect to socks server? I want to set firefox socks host to server ip and port, instead of 127.0.0.1 and the port specified with -D parameter.


title: List iptables rules as append command

text: A while back I was watching over the shoulder of a Linux guru and he issued a command that listed all the iptables rules in the format of the append commands you would need to issue in order to build them, but despite all my googling and man page searching I can't figure out what he did. For example if the output from `iptables -nL INPUT` was:               Chain INPUT (policy DROP)     num  target     prot opt source               destination     1    ACCEPT     tcp  --  0.0.0.0/0            192.168.0.1           tcp dpt:80      The output from the command I'm looking for would be something like:               1  -A INPUT -i eth0 -p tcp --dport 80 -d 192.168.0.1 -j ACCEPT      I seem to remember that it was just another option passed into the standard `iptables -L` command, but I could be wrong. Does anyone know of a command to accomplish this?


title: What is and how to use PS1 \#

text: I put this is .bashrc               # colors     NC="$(tput sgr0)"     RED="$(tput setaf 1)"     GREEN="$(tput setaf 2)"     # etc ...          PS1="\[$BROWN\]\u \[$CYAN\]#\# \[$PINK_BLD\]!\!\[$NC\] \[$BLUE\]\W: \[$NC\]"      So               deepo #50 !545 ~: echo "This is an example what it will look like."      What is, and how do I use, the hash 50 indication? There are many pages on how to do the PS1 (e.g., http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html) but from fast searches of those I get only standard descriptions of the hash thing (in this case, "the command number of this command").


title: Capture output of a bash command, parse it and store into different bash variables

text: **Explanation:** I have a small _bash_ script which simply runs _any_ Linux command (e.g. say `ifconfig`) The typical output of _ifconfig_ is something like this:               eth0      Link encap:Ethernet  HWaddr 30:F7:0D:6D:34:CA               inet addr:10.106.145.12  Bcast:10.106.145.255  Mask:255.255.255.0               inet6 addr: fe80::32f7:dff:fe6d:34ca/64 Scope:Link               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1               RX packets:1104666 errors:0 dropped:0 overruns:0 frame:0               TX packets:2171 errors:0 dropped:0 overruns:0 carrier:0               collisions:0 txqueuelen:1000               RX bytes:444437904 (423.8 MiB)  TX bytes:238380 (232.7 KiB)          lo        Link encap:Local Loopback                inet addr:127.0.0.1  Mask:255.255.0.0               inet6 addr: ::1/128 Scope:Host               UP LOOPBACK RUNNING  MTU:16436  Metric:1               RX packets:15900 errors:0 dropped:0 overruns:0 frame:0               TX packets:15900 errors:0 dropped:0 overruns:0 carrier:0               collisions:0 txqueuelen:0               RX bytes:467306 (456.3 KiB)  TX bytes:467306 (456.3 KiB)      Now what most people usually do is store the _entire_ output into a file/variable and parse based on that. I however want to know if there is anyway that I could put _specific_ parts of the output in more than one variable (say a _bash variable_ called `${IPETH0}` to carry the IP address `10.106.145.12` from _eth0_ and `${IPLO}` to carry the IP address `127.0.0.1` from _lo_ in the above example _without running ifconfig command twice_ ). Something like what _tee_ command does with the input but I want to do this for the _output_ and store the output into 2 or _more_ variables in one go. Any ideas?


title: How do I generate a list of the characters occurring before a certain character only in lines that contain another certain character using regex?

text: I know that's super confusing (total noob-sorry!). To clarify, I have a text file that looks like this:               407-OL?     408-2-OL?     408-OL?     418-het?     420-1 and 2- OL?     429-2-left unscored?     430-2-left both unscored?     431-1 and 2- Ri??     436-1-just homozygote?     444-2-het? ins. both     456-2-ins 246 despite slight OL     456-1-ins 245 (weaker)     457-2-Ri?      I want it to return the numbers on the left (before the dash), but only for lines that contain a question mark. In other words, I want this to be the output:               407     408     408     418     420     429     430     431     436     444     457      Any suggestions would be amazingly helpful! Thank you!


title: Open and redirect port

text: I'm trying to set up SNMP for a router so I can monitor it from an existing Nagios installation on an off-site server. I'm having trouble getting the router to respond to SNMP requests from the WAN, despite trying a few different iptables rules. The router is a new ASUS RT-AC66U, running AsusWRT 3.0.0.4.270.26 (Merlin build). I was very recently and unfortunately forced to switch to Comcast as an ISP, and they say that they block port 161 and 162 across the network. In light of that, I'm trying to redirect 1610 to 161. I currently have port forwarding set up for my NAS, 1611->161, and SNMP works just fine there. The first thing I tried was setting up a port forwarding rule from 1610->127.0.0.1:161 (UDP), which didn't seem to work:               [ssube@centos-server ~]$ snmpwalk -v 2c -c [name] [ip]:1610     Timeout: No Response from [ip]:1610          [ssube@centos-server ~]$ snmpwalk -v 2c -c [name] [ip]:1611     SNMPv2-MIB::sysDescr.0 = STRING: Linux Triton 2.6.32.12 #2668 Tue Dec 11 12:36:30 CST 2012 armv5tel     SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10      The NAS rule is working just fine, as you can see above. Removing the NAS rule and replacing 1610 with 1611 in all the router rules didn't seem to help. The error message (no response) has been consistent regardless of what I try. My second attempt was to go through iptables itself. I set up the following rules:               boss@RT-AC66U:/jffs/scripts# cat firewall-start     #!/bin/sh          iptables -I INPUT 1 -p udp --dport 1610 -j ACCEPT     boss@RT-AC66U:/jffs/scripts# cat nat-start     #!/bin/sh          iptables -t nat -A PREROUTING -p udp --dport 1610 -j REDIRECT --to-port 161      From within the LAN, I can see the router just fine:               ssube@KRAKEN /c/Program Files/ConEmu > snmpwalk -v 2c -c [name] 192.168.1.1:1610     SNMPv2-MIB::sysDescr.0 = STRING: Linux RT-AC66U 2.6.22.19 #1 Sun Mar 17 17:16:27 EDT 2013 mips     SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10      However, I still can't see it from outside of the LAN, with or without the INPUT chain rule. Both rules appear in iptables:               boss@RT-AC66U:/tmp/home/root# iptables -L     Chain INPUT (policy ACCEPT)     target     prot opt source               destination     .....     ACCEPT     udp  --  anywhere             anywhere            udp dpt:1610      (listed before any DROP rules, after a few unrelated ACCEPTs)               boss@RT-AC66U:/jffs/scripts# iptables -t nat -L     Chain PREROUTING (policy ACCEPT)     target     prot opt source               destination     VSERVER    all  --  anywhere             [ip].comcast.net     REDIRECT   udp  --  anywhere             anywhere            udp dpt:1610 redir ports 161      Still, no luck on external SNMP. I've tried tcpdump to see if the packets are making it in at all, but running tcpdump on the router seems to kick me off wifi within a few seconds, and I haven't had a chance to plug into the router and run it there yet (will edit with updates when I do). The scripts seem to be working, since the rules appear. I suspect the issue is with the rules, but am having a hard time pinning it down, and have yet to get a response on the firmware message board.


title: How to restrict directory name creation to pattern?

text: I have FreeNas `CIFS` share. Mount command result:               /dev/ufs/VSPHERE on /mnt/VSPHERE (ufs, NFS exported, local, soft-updates, nfsv4acls)      I want to restrict users from creating directories that do not fit to pattern: `YYYY-MM-DD` (year-month-day). Users are using Windows to access CIFS share from network on `\\\freenas\cifs\`. They see `\\\freenas\` in network places. They go to `\CIFS\foo\` directory, then they can create any directory they want. That's is the problem. They should have create directory that meets `YYYY-MM-DD` pattern. Users don't need to login to access this share, it's using FreeBSD `ftp:nogroup` account so I can apply restriction to that user in FreeBSD directly (FreeNas)?


title: How to make any file and put contents in that using script

text: I want to modify `configure.sh` to create a file `/etc/pam.d/XXX` with some predefined content. How can I do this by putting the file's absolute path and content in configure.sh? Please explain the syntax.


title: Command to 're-apply' previous command?

text: Is there an easy way to re-apply a previous command to a new command line entry? Say I typed in `chmod u+r,g+x file.txt` but forgot the sudo. Could I simply type `sudo <some easy symbol>`'? Pardon for the possible noob question.


title: USB device to be detected at the "same" /dev point always?

text: In Linux _(actually I'm with CentOS v6.5)_ , whenever I plug in my `USB Terminal/Character Device` _(some kind of USB Adapter)_ for the first time (after booted), it is detected at:               /dev/ttyUSB0      But whenever I plug it OUT and IN again, it is again detected at:               /dev/ttyUSB1      The one and only same device. That is making me problem with some configurations in my Applications.   * Meaning that sometime i am (i need to) plugging IN and OUT in **runtime**. How do I make such USB Device _(which is first ever detected)_ to be **always** detected at `/dev/ttyUSB0` (At " _Zero_ " or whatever **always** at the **same** number.)


title: How to pipe a remote file to stdout over scp or sftp?

text: Using ssh, it is easy to print the contents of a file using               ssh host 'cat file.txt'      When ssh is disabled, and only SFTP is enabled, running the previous command gives the following error: > This service allows sftp connections only. To work-around this issue, I could create a temporary file using `scp` or `sshfs` (as shown below), but that looks really ugly. What is the proper way to print the contents of a remote file when SSH is disabled?               mkdir tmpdir     sshfs host: tmpdir     cat tmpdir/file.txt     fusermount -u tmpdir          # This does not work! scp -v host:file.txt . shows     # "Sink: This service allows sftp connections only."     scp host:file.txt .     cat file.txt     rm file.txt


title: LD_PRELOAD or similar to prevent network access

text: I'd like to start a program disconnected from the network (because immediately upon starting it tries to download huge amounts of data, which can be prevented by changing settings as soon as it settles down). However, I really don't want to actually _bring the network down_ for this one program. Is there some LD_PRELOAD or similar to give the program the impression that the network is down? I'd rather not create a virtual machine.


title: File permissions and saving

text: Let's say you open a file on which you have write permission. Meanwhile you change permissions and remove write permission while you still have the file open in some editor. What will happen if you edit and save it?


I'm using Opensuse 12.3.   systemd-195-13.45.1.x86_64 After few problems when I added a disc at btrfs mount I'm trying put my system in emergency mode (which I consider all services will be stopped and all mounts able to be unmounted),. But they just don't work!!! **How to force systemd enter in emergency mode?** (or something equivalent of init single mode) and force the emergency mode at boot time(grub menu)? **First attempt:**   I use the old way : `init 1` at the console...   They show me the emergency screen , ask for root password, but after this re- login, I still unable to unmount my btrfs FS (says it are in use). (with lsof I don't found anything using this mounts).   The `runlevel` command return level 3... not 1... **Second attempt:**   I run the command `systemctl emergency` which show me the "emergency screen" , ask for root password... and then finally show me runlevel = 1 . But I'm still not able to umount my btrfs FS.... **Third attempt:**   I reboot the machine and at grub screen I type 'e' to add the "emergency" word at the options. Where they give me a message like "emergency word is invalid". I try with "single" word and get the same behave.... * * * My final solution was remove the automatically mount from fstab and reboot my system at normal mode. Then finally I able to run my check at btrfs Fs... but is very annoying because all services which depends this mount start give errors...


title: How to test if command is alias, function or binary?

text: I have command `foo`, how can I know if it's binary, a function or alias?


title: Get OpenSSL FIPS Module Version Number

text: Is there a way for a user to determine _what version_ of the FIPS module was compiled into OpenSSL? When I say "as user", I mean is there some functionality buried in the command line interface to get this information. I know that I can tell that the FIPS module was built-in using the following:               # openssl version     OpenSSL 1.0.1g-fips 7 April 2014      But what I really want to know is the value of `FIPS_MODULE_VERSION_TEXT`, which, in my case, would be 2.0.6.


title: How to customize PS1 properly?

text: I customized my bash with this in my bashrc               export PS1="\e[0;36m\h\e[m \e[0;33m\w/\e[m \e[0;31m\n\$ →\e[m  "      So I get something like this (with colors) :               Ahuri ~/Public/      $ →        But I am having problems with long commands. When I write a very long command that is longer than a line it starts overwriting my first line Example :               Ahuri ~/Public/      $ → ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      If I continue to add "^" I get:               Ahuri ~/Public/      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      my "$ →" is overwritten, and then the whole line gets overwritten.


title: Grep a string from file

text: I have 5 filenames created inside a folder for one operation.The filenames are in the following format.               ES_currentdate_currenttime_processid_uniqueid.log      I want to read the status from the latest created file in that path. The way I form the filename in shell script is:               $ filename=ES_*_uniqueid.log     $ echo grep "##status##XRB##" $HOME/log/$filename | sort -u` "      When I `grep` it reads the status from all 5 files and echoes it. I want the string to be `grep` only from the latest file that got created. Could some one provide a solution?


title: What is the pipe character "x|y)" in the case statement?

text: In a script `/etc/network/if-up.d/avahi-autoipd` in my system, I find statements like this:               case "$ADDRFAM" in       inet|NetworkManager) ;;       *) exit 0     esac          case "$METHOD" in     static|dhcp|NetworkManager) ;;     *) exit 0     esac      The pipe character `|` seems like the logic "or", but I can't find this rule in the guide. I can only find `|` used as the command pipe and the "bitwise or" for the arithmetic integer. Can anyone tell me what's the usage in this case?


title: Debugging iptables using live packet views

text: Are there any CLI or GUI functions that I can use to monitor hits to `iptables` and watch as packets interact with `iptables`?


title: Keep running program requiring X server after logging off of ssh session

text: I have a python script that periodically generates a png image, and puts it on a server that I can access through a browser. The image displays the progress of a job I am running on the server. I'm using matplotlib to generate the images. The python script goes to sleep after generating each image. After an hour, it wakes up, generates a new image, and then goes back to sleep. I start the script over an ssh session. When I log off, the script gets killed. I've read the other threads covering this problem, but the proposed solutions do not work. The script is killed after I log off, even if I run it with               nohup script.py &> job-monitor.log &      or if I run it like this               script.py     [Ctrl-Z]     disown -h %1     bg 1      The strange thing is, when I log off and log back in, the script is no longer running, and job-monitor.log is empty. What could be happening, and how do I get the script to continue running after I log off? Additional information: I think the problem has to do with the plotting library I'm using, matplotlib. I think it may require an X session to produce a png, even though the graphic is just being saved to disk.


title: Why am I getting "no boot disk has been detected" after installing Linux?

text: After installing a Linux distro (Fedora 19, to be exact) on a Windows 8 machine I got the message: > No boot disk has been detected or the disk has failed. What did I do wrong?


title: Twinview: 2 monitors difference resolutions with NVIDIA

text: I'm successfully using twinview to drive 2 monitors for my home theatre computer (one in the case, one projector). I recently upgraded my projector and now the two screens have vastly different resolutions (1920x1200, 848x400). As a result twinview is forcing me to use very little of my projector resolution (scaling up a fuzzy image), OR, overdrive the little screen until is shuts off with "OUT OF RANGE" message but have a great projector image. I would like to drive the projector at full resolution, and have the (nvidia) driver/X scale this same image down to 848x400 for my small screen. Is this possible? I'm running Centos 6.3 x64 with X.


title: How can I redirect outbound traffic to port 80 using iptables locally?

text: I'm trying to locally redirect ports on my Ubuntu machine using `iptables`. Similar to transparent proxying. I want to catch anything trying to leave my system on port 80 and redirect it to a remote host and port. Can I achieve this using the NAT and pre-routing functions of `iptables`?


title: How to add a path to system $PATH for all users's non-login shell for debian

text: After installing some programs in `/opt/xxx/bin`, I want to add `/opt/xxx/bin` to system `$PATH` for all users's non-login shell. What should I do?


title: I cannot install new packages: "Could not get lock /var/lib/dpkg/lock"

text: I am new to Linux (installed Ubuntu for the first time yesterday), and have never dealt with any unix-based OS. I started using Linux for the sole purpose of collaborating code with my partners via git. I first needed to install jdk/jre. However, when i tried to install it, like so:               ben@ubuntu:~$ sudo apt-get install openjdk-7-jre-headless      I got this message:               E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)     E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?      I cannot get git to install either, so I don't think it is a problem with the specific package I selected. Can someone explain what that error means, and how to deal with it? Any help is greatly appreciated.


title: Linux max threads count

text: my server has been running with Amazon Ec2 linux. I have a mongodb server inside. The mongodb server has been running under heavily load, and, unhappily , I've ran into a problem with it :/ As known, the mongodb creates new thread for every client connection, and this worked fine before. I don't know why, but MongoDB can't create more than 975 connections on the host as a non-privileged user ( it runs under a mongod user) . But when I'm running it as a root user, it can handle up to 20000 connections(mongodb internal limit). But, further investigations show, that problem isn't the MongoDB server, but a linux itself. I've found a simple program, which checks max connections number:               /* compile with:   gcc -lpthread -o thread-limit thread-limit.c */     /* originally from: http://www.volano.com/linuxnotes.html */          #include <stdlib.h>     #include <stdio.h>     #include <unistd.h>     #include <pthread.h>     #include <string.h>          #define MAX_THREADS 100000     #define PTHREAD_STACK_MIN 1*1024*1024*1024     int i;          void run(void) {       sleep(60 * 60);     }          int main(int argc, char *argv[]) {       int rc = 0;       pthread_t thread[MAX_THREADS];       pthread_attr_t thread_attr;            pthread_attr_init(&thread_attr);       pthread_attr_setstacksize(&thread_attr, PTHREAD_STACK_MIN);            printf("Creating threads ...\n");       for (i = 0; i < MAX_THREADS && rc == 0; i++) {         rc = pthread_create(&(thread[i]), &thread_attr, (void *) &run, NULL);         if (rc == 0) {           pthread_detach(thread[i]);           if ((i + 1) % 100 == 0)         printf("%i threads so far ...\n", i + 1);         }         else         {           printf("Failed with return code %i creating thread %i (%s).\n",              rc, i + 1, strerror(rc));                // can we allocate memory?           char *block = NULL;           block = malloc(65545);           if(block == NULL)             printf("Malloc failed too :( \n");           else             printf("Malloc worked, hmmm\n");         }       }     sleep(60*60); // ctrl+c to exit; makes it easier to see mem use       exit(0);     }      And the sutuation is repeated again, as root user I can create around 32k threads, as non-privileged user(mongod or ec2-user ) around 1000 . This is an ulimit for root user:               core file size          (blocks, -c) 0     data seg size           (kbytes, -d) unlimited     scheduling priority             (-e) 0     file size               (blocks, -f) unlimited     pending signals                 (-i) 59470     max locked memory       (kbytes, -l) 64     max memory size         (kbytes, -m) unlimited     open files                      (-n) 60000     pipe size            (512 bytes, -p) 8     POSIX message queues     (bytes, -q) 819200     real-time priority              (-r) 0     stack size              (kbytes, -s) 8192     cpu time               (seconds, -t) unlimited     max user processes              (-u) 1024     virtual memory          (kbytes, -v) unlimited     file locks                      (-x) unlimited      This is an ulimit for mongod user:               core file size          (blocks, -c) 0     data seg size           (kbytes, -d) unlimited     scheduling priority             (-e) 0     file size               (blocks, -f) unlimited     pending signals                 (-i) 59470     max locked memory       (kbytes, -l) 64     max memory size         (kbytes, -m) unlimited     open files                      (-n) 60000     pipe size            (512 bytes, -p) 8     POSIX message queues     (bytes, -q) 819200     real-time priority              (-r) 0     stack size              (kbytes, -s) 1024     cpu time               (seconds, -t) unlimited     max user processes              (-u) 1024     virtual memory          (kbytes, -v) unlimited     file locks                      (-x) unlimited      Kernel max threads:               bash-4.1$ cat /proc/sys/kernel/threads-max      118940      SELinux is disabled. Don't know how to solve this strange problem...Possibly, somebody does?


title: How do I make an ISO copy of a DVD movie?

text: I want to make backups of data and video DVDs, without recompressing or altering them. I just want an ISO that I can mount to act as if I inserted the DVD (this includes video DVDs). I had previously used K9copy 2.3.6, which seemed to work fine except that every other DVD would have no sound when mounted and played like a DVD. I've now installed `dvdrip` but it seems more aimed at producing compressed video files with an interface that's somewhat more complicated than necessary for what I'm trying to do. I tried using `dd` but it just comes up with a `disc not readable` result or something similar, even thought the disc is fine.


title: Is there a central repository of SSH keys on a system? Does SSH keygen put the private key in that location?

text: I just generated a public and private key with ssh key gen. I uploaded the public key onto a gitlab (basically a clone of git hub) system for my university and got an email saying that I successfully uploaded the key. When I try to run a git clone command, I get               Cloning into 'csci6990-hci-f13'...     ssh_exchange_identification: Connection closed by remote host     fatal: The remote end hung up unexpectedly      I am trying to understand if I did everything properly before blaming the git lab system. With that said, when I uploaded a public key onto git lab there were no instructions/steps for telling gitlab where the private key resides in on my mac os x. This makes me think that maybe sshkeygen automatically puts the key into some kind of standard repository location? Is that the case? If not, then how can I upload a public key and have it work without telling the remote system where the corresponging private key sits within the file system? Edit: this is the output of ssh -vvv               OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011     debug1: Reading configuration data /etc/ssh_config     debug1: Applying options for *     debug2: ssh_connect: needpriv 0     debug1: Connecting to gitlab.cs.uno.edu [137.30.120.92] port 22.     debug1: Connection established.     debug1: identity file /Users/abramhandler/.ssh/id_rsa type -1     debug1: identity file /Users/abramhandler/.ssh/id_rsa-cert type -1     debug1: identity file /Users/abramhandler/.ssh/id_dsa type -1     debug1: identity file /Users/abramhandler/.ssh/id_dsa-cert type -1     ssh_exchange_identification: Connection closed by remote host


title: Get device with major number 0 (btrfs subvolume)

text: When I stat a file on a btrfs subvolume I get a major device number of `0`. Is there a reliable way to find the mount point of this device, without knowing in advance it is a btrfs subvolume? e.g. I'd like to be able to do this in python:               >>> st = os.stat('a file')     >>> os.major(st.st_dev)     0     >>> os.minor(st.st_dev)     38     >>> os.path.exists('/sys/dev/block/0:38')     False     >>> magic_method_that_gets_mount_point(0, 38)     '/home'     >>> magic_method_that_gets_mount_point(8, 1)     '/boot'      (in my case `sda1`(`/sys/dev/block/8:1`) is mounted on `/boot`, and `/home` is a btrfs subvolume of `sda2`). # Edit I'd need to be able to do this without knowing the path of the file. Above I used `os.stat` as an example however the information is actually retrieved from an `ioctl` call to a loop device which returns:               struct loop_info64 {         uint64_t    lo_device;         uint64_t    lo_inode;         uint64_t    lo_rdevice;         uint64_t    lo_offset;         uint64_t    lo_sizelimit;         uint32_t    lo_number;         uint32_t    lo_encrypt_type;         uint32_t    lo_encrypt_key_size;         uint32_t    lo_flags;         uint8_t     lo_file_name[64];         uint8_t     lo_crypt_name[64];         uint8_t     lo_encrypt_key[32];         uint64_t    lo_init[2];     };      There is the field `lo_file_name` however it has a max length of 63 chars so cannot be relied open. I am also aware of `/sys/block/loopX/loop/backing_file`, however this is only available in Linux >= 2.6.37 and my code needs to run on CentOS 6 (2.6.32). # Edit #2 My ultimate goal here is to be able to find the backing file for a loop device reliably. Even util-linux does not do this on kernels < 2.6.37, e.g.               > dd if=/dev/urandom bs=4096 count=256 of=/root/a_really_really_really_really_really_really_really_long_file_name.img     256+0 records in     256+0 records out     1048576 bytes (1.0 MB) copied, 0.137397 s, 7.6 MB/s     > LD=`losetup -f --show /root/a_really_really_really_really_really_really_really_long_file_name.img`     > losetup $LD     /dev/loop1: [fd00]:922372 (/root/a_really_really_really_really_really_really_really_long_*)      Notice that the filename is truncated, this is because util-linux uses the `loop_info64` struct which has a 63 char limit on the `lo_file_name` field. What I can get reliably is the device ID and the inode number of the backing file. This is where I hit a wall, as the backing file is stored on a btrfs subvolume.


title: Generation of UUID1 is too slow

text: I upgraded my Ubuntu box from 13.04 to 14.04 LTS few days ago. Now I'm using libuuid-2.20.1. Anyway, after the upgrading, my UUID1 became very slow.               $ time uuidgen -t     f22c36aa-f511-11e3-9437-080027e59ea0     uuidgen -t  0.71s user 0.67s system 99% cpu 1.387 total          $ time uuidgen -t     fea4537c-f511-11e3-a6d5-080027e59ea0     uuidgen -t  0.72s user 0.67s system 99% cpu 1.394 total      0.7 seconds elapsed in `uuidgen -t`. What can make it slow? -- updated -- Here's my `w` result:               $ w      09:48:55 up 5 days, 22:56,  3 users,  load average: 0.37, 0.43, 0.43     USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT     sub      :0       :0               Wed10   ?xdm?   2days 22.69s init --user --state-fd 41 --re     sub      pts/26   sub.local        Wed18   16:47  17.00s 10.07s vim -b -b test/test_item.py     sub      pts/27   sub.local        Wed18    7.00s  8.63s  0.02s w


title: zsh's "echo SomeText >> **/filename" in other shells

text: I need to fill all files with a specific filename (recursively) with a text. In zsh this can be done with               echo SomeText > **/TheFileName      I search generic solutions for sh-compatible and/or tcsh shells. Is there a shorter/easier way than the following command?               find . -name "TheFileName" -print0 | xargs -0 sed -n -i -e '1c\nSomeText'


title: Failure to startx on Ubuntu 14.04 after security update - missing libXfont.so.1

text: I had Ubuntu 14.04 running perfectly on my system and then it underwent a recommended security update. I let it update while I was at work and when I returned I found a black screen stating, "No init found" and "mount: mounting /dev/mapper/ubuntu-root on /root failed: Invalid argument". I followed some guides and ran the following commands:               ls /dev/sd*     sudo apt-get install lvm2     sudo pvscan     sudo vgscan     sudo vgchange -a y ubuntu-vg     sudo fsck /dev/ubuntu-vg/root      After running those commands and rebooting, my Linux system was back up and running again; however, not quite like it was before. It starts up into command line mode (without GUI) and asks for my username and password. When I log in and try "startx" I get the following:               user@home-pc:~$ startx     xauth:  timeout in locking authority file /home/user/.Xauthority     xauth:  timeout in locking authority file /home/user/.Xauthority          /usr/bin/X: error while loading shared libraries: libXfont.so.1: cannot open shared object file: No such file or directory     xinit: giving up     xinit: unable to connect to X server: Connection refused     xinit: server error     xauth:  timeout in locking authority file /home/user/.Xauthority     user@home-pc:~$       I get the same message when I try "sudo startx". I believe this error is due to the symbolic link that is used to identify the "libXfont.so.1" file, but I don't know how to fix this problem. I already tried running "sudo apt-get update && sudo-apt-get dist-upgrade" in hopes that this would fix or finish the upgrade and/or installing of the security update, but this didn't fix the problem. Does anyone have any idea on what is going on or how I can fix this?


title: How batch mv files to folders created and named by modification date?

text: I am quite new to the terminal stuff and I just couldn't find any answer on the aforementioned subject. On my OS X, I have a folder with about 4000 pics that I'd like to move into folders that are named according to the modification date (not creation date) of the files. How can I accomplish this using the terminal?


title: Resize partitions with gparted

text: Hey I'm trying to resize my boot partition and eventually my LVM partition. I currently have:               /dev/sda1 ext2         243M       /dev/sda2 extended     7.76G       unallocated            17G        Ideally I'd like:               /dev/sda1 ext2         7.2G       /dev/sda2 extended     17.76G      My main problem is my `/` that is too small and I can't install anything anymore. I tried to resize `/dev/sda1` but the max size is the current one. As I understand it, I need to move the `unallocated space` next to `/dev/sda1` but Gparted doesn't let me. Any ideas? ![enter image description here](http://i.stack.imgur.com/qme9r.png)


title: Which fonts preinstalled on Linux are the same as that on Windows 7+?

text: Which fonts are common in default Linux and Windows installation? Are there any? Do these operating systems share any identical fonts? Or all fonts are different and there are no common fonts in default?


title: How to make `sudo` preserve $PATH?

text: I need to run a program installed on /opt/godi/sbin (a custom directory). If I add that directory to my PATH, by adding the following line to my .bashrc file               export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin      then I can try to run the command just fine (except that it fails because it needs sudo). However, when I try to use sudo:               sudo godi_console      I get the following error               sudo: godi_console: command not found      Inspecting the PATH variable after using sudo reveals that its not including the same PATH I have as a normal user:               $ sudo sh     # echo $PATH                      /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin      Why is the PATH not the same? Am I doing something wrong? I'm on Debian Jessie and unfortunately I cannot get around the issue by passing sudo the the absolute link to godi_console because godi_console itself also depends on the PATH being correctly set.


title: Mounting windows share using mount -t cifs

text: All, I have a SUSE SLES 11 box running samba. I am running this command:               mount -t cifs //ip/dir1/dir2 /mnt/backups -o username=user,password=pwd,domain=domain      Which works and mounts the drive properly. I can access all contents of dir2 via               ls /mnt/backups      Now I use used umount /mnt/backups, and try to access a directory deeper...               mount -t cifs //ip/dir1/dir2/dir3 /mnt/backups -o username=user,password=pwd,domain=domain      The command does not return any errors, but when I type _ls /mnt/backups_ , I get               /bin/ls: /mnt/backups: No such file or directory      The permissions on all folders in the directory are fine. When I am able to mount dir2, I can navigate to the dir3 using ls. However, I cannot mount dir3. Is there a restriction on how deep you can go (as far as directories)?


title: Can I install libXcomposite.so without the root permission?

text: I got this error when I execute dropbox on CentOS. > ImportError: libXcomposite.so.1: cannot open shared object file: No such > file or directory I don't have a root account. Output of `uname -a`: > Linux version 2.6.18-308.24.1.el5 (mockbuild@builder17.centos.org) (gcc > version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Tue Dec 4 17:43:34 EST > 2012


title: is there something like a per-user daemon?

text: I need to run some background processes that live as long as I am logged in with a certain user. Does there exist something like a per-user daemon? I know only of global daemons that live from computer startup 'till shutdown (or manual startup/kill). for now I made a script that checks if the process already exists and creates the process if it doesn't. This script is then run with the `nohup` command from my `.profile`. This way the process launches on startup, and is only launched once (even with multiple `rxvt` terms coming and going). Yet, it never gets killed after I log (which isn't a disaster but it is cleaner to also terminate the process).


title: Reorder fields/characters with cut command

text: > **Possible Duplicate:**   >  Combining 2 different cut outputs in a single command? I have One file - temp.txt - which contains               ABCDF          PQRST          LMNOP      I tried this `cut` command               $ cut -c 2-5 temp.txt     BCDF          QRST          MNOP      output is right.               $ cut -c 1,2,3,4 temp.txt     ABCD          PQRS          LMNO      output is right. But when I change sequence, meaning               $ cut -c 2-4,1 temp.txt     ABCD          PQRS          LMNO      above output displayed. but logically output is               BCDA          QRSP          MNOL      so my question is how this happen ,any reason behind that.


title: Is it safe to pipe the stdout of A to B in parallel

text: I'm running `A file | B --params > file.txt`. Since I want to accelerate the processing speed, I used the `parallel -j+0< a.txt` to run 20 jobs concurrently. a.txt contains all the commands:               A file1 | B --params > file1.txt           A file2 | B --params > file2.txt          A fileN | B --params > fileN.txt      Is this way safe? Will the stdout from different programs be messed when running in parallel?


title: can I make a vagrant multi machine vm depend on another

text: So we have a database vm that we always want to start, we also have a vm that works for a distributed configuration, that we only want to start when we're testing that. My problem is I want the database vm to start if it's not when I'm starting the distributed vm               ...     config.vm.define "oracle", primary: true do |oracle|     ...     config.vm.define "distributed", autostart: false do |distributed|     ...      so when I do `vagrant up` that should just start `oracle`, but when I do `vagrant up distributed` that should start `oracle` and `distributed`. right now the latter just starts `distributed`.


title: How do I recover from "chown -R myuser /usr" on OSX?

text: I installed git and ruby 2.0 using homebrew then terminal immediately stopped working. On opening, it gives me the following error:               login(89809,0x7fff7bac5960) malloc:      *** error for object 0x7fc7cb500b40: pointer being freed was not allocated     *** set a breakpoint in malloc_error_break to debug     [Process completed]      Before that I ran a 'chown' on everything under /usr to a non root user


title: Iptables and Port Scanning and Recent module

text: I'm trying to write an adaptive firewall using iptables, and am not clear on how the recent module is working. For example, see http://blog.zioup.org/2008/iptables_recent/ Snippet from my iptables:               ...input stuff, established, etc...     -A INPUT -m conntrack --ctstate NEW -j limiter     ... more input stuff...     # very end of chain, nothing matches. Likely unauthorized port     -A INPUT -m conntrack --ctstate NEW -m recent --name PORTSCAN --set          # limiter table     -A limiter -m recent --update --name PORTSCAN     -A limiter -m recent --rcheck --name PORTSCAN --hitcount 10 --seconds 300 -j LOG      This setup works. Watching /proc/net/xt_recent/PORTSCAN, running nmap on a closed port adds my ip, and then trying to connect to, say, port 80 (which is open) updates the list. Additionally, if I connect to just open ports, I am not added to the list. My question is, when I try to combine the two lines in the limiter table into one, it no longer works.               #-A limiter -m recent --update --name PORTSCAN     #-A limiter -m recent --rcheck --name PORTSCAN --hitcount 10 --seconds 300 -j LOG     -A limiter -m recent --update --name PORTSCAN --hitcount 10 --seconds 300 -j LOG      Scanning an open port after a closed one does not update the list (although if the limit of 10 packets/300 secs is overrun, it is logged). My understanding was that the update line would be equivalent to the other two. Why not?


title: identify files with non-ASCII or non-printable characters in file name

text: In a directory size 80GB with approx 700,000 files, there are some file names with non-English characters in the file name. Other than trawling through the file list laboriously is there:   * An easy way to list or otherwise identify these file names?   * A way to generate printable non-English language characters - those characters that are not listed in the printable range of `man ascii` (so I can test that these files are being identified)?


title: Bash script to delete a file called index.html recursively

text: I need a bash script (not sure how to write the actual .sh file) which I could set to be run by cron every minute and that would delete files with the name `index.html` that are in a specific directory and its subdirectories. I believe that the following command will do that. However, I need to write it as a script file which I could then have executed via cron. `find /path/to/directory -name "index.html" -print0 | xargs -0 rm -rf` The `/path/to/directory` would be relative to the server root. My two questions are, do I need a trailing `/` at the end of the path and how do I write the bash script file for example in a file called `deleteindexes.sh`. I am assuming that I would need to set the file as an executable using `chmod a+x deleteindexes.sh` As regards setting the `cron` command, that is not a problem for me.


title: How do I create an RPM package that would fail a YUM transaction if certain creteria are met

text: I'm trying to package a product consisting of many packages. I'm successful with writing all the spec files, the dependencies between the packages and so on. They're all installed and work fine. The one thing I do not succeed to do, is to run a pre-requisition test: In certain cases, I would like the packages not to be installed at all, and the user getting an error, explaining him what he needs to fix first, before he runs the packages installation. For example: I want to verify that the user is running in runlevel 3, and if not, abort the whole installation, and ask the user to re-install CentOS in "Minimal" profile - as I don't want all the extra packages that comes with "Desktop". (This is just an example, I have a few such tests to perform). The way I approached this problem is this: I've created a sort of 'meta package', that its name appears in all the other packages 'Requires:' directive, so it would be installed first by YUM, and in that package spec file, in the `%pre` section, I did the various tests I wanted to perform, outputting test errors when applicable, and then '`exit 1`'. The reason I chose this approach is this: "If every package depends on this package, and this package cannot be installed, the transaction must fail, as soon as the package manager wants to install a package that depends on a package that failed installation... after all, the dependency has not been met". In Gentoo, for example, if a package fails installation, for whatever reason, emerge stops completely - even not for dependency issues; And there's a special flag to tell emerge to continue despite the error returned from one of the packages. The problem is that indeed the package fails when the tests fails (RPM specifically says that it returned code 1), BUT... YUM doesn't really seem to care that this happens - and just continues to install everything else, including packages that depend on a package that is not installed (!). At the very end, it simply reports that all the packages were installed successfully, expect for the package that deliberately failed... I'm guessing that the reason for that is that dependency checking happens before the transaction begins, and indeed, dependencies are met from the various repositories at YUM's disposal. Still, it does not make any sense to me that if a dependency eventually failed, the installation of dependent packages would continue. Is my logic flawed? I doubt it's a bug, as someone would have encountered it by now (this is on CentOS 6.3 if it matters...) - but all my Google-foo yielded nothing. I didn't even find someone asking the same question... maybe I'm using the wrong keywords? Am I approaching this wrong way? Any other idea (that fits into RPM specs or other YUM repository magic, even at the YUM .repo file... - but all contained within the YUM infrastructure, without external scripts to run before 'yum install') - would be greatly appreciated!


title: Tunnels to the same port number

text: I have an application that connects to several hosts on the same port:               a.protected:123     b.protected:123      I don't have direct access to either of them, but I can make a ssh tunnel (through `x.accessible`). Should the ports have been distinct, I could have make the tunnel to the same port number:               ssh -f me@x.accessible -L 123:a.protected:123 -N      And then I would have added a.protected as an alias to localhost, in `/etc/hosts` But given that more hosts use the same port number, what are my options? How can I use tunnels to get the application to connect to them, without changing the application?


title: Desktop launchers not getting scanned by Gnome

text: I'm running Fedora 20 on my notebook, and recently I removed some of the Gnome session startup apps which (I believe this was the cause) resulted in my `~/.local/share/applications/` directory not being scanned anymore - any changes in this directory don't get populated in Gnome menu. How can I get this functionality back? I have no idea what Gnome background app is responsible for this.


title: Install MySQL from Bash Script

text: I'm coding a bash script to automate the process of deploying VPS servers but I'm having some trouble while trying to install MySQL from either `aptitude`/`apt-get` or `yum`, this is what I have so far:               if [ "$OS" == 'centos' ]; then         yum -y install  mysql-server > /dev/null 2>&1     elif [ "$OS" == 'ubuntu' ]; then         aptitude -y install mysql-server > /dev/null 2>&1     fi      It seems that the script keeps running ad infinitum, I suspect the problem is because the `mysql-server` package seems to bring up a wizard to specify the MySQL root password, but I've no idea how to overcome or fill the password from within the script. Does anyone know how I can work around this problem?


title: Need further explanation on TIME_WAIT

text: Hi Unix/Linux Gurus out there! I need a solid proof that TIME_WAIT (a lot of it actually) is the real culprit in the slowdown in one of our servers. The server is hosted on Parallels Baremetal virtualization, and the actual server is a VM: CentOS5 with dual CPU and 2GB RAM. A week ago, we started to notice that it was too slow that even doing an 'ls' on a directory with just a few files in there (around 20) would need around 1.5 seconds to display the results. I tried doing `vmstat` but it doesn't seem to be even using it's swap. No bottlenecks on the network. But running `top`, you'd see java mostly hogging the resource. Java is needed since this VM is our hudson server. One of my colleagues tried checking the connections via               $ vmstat -vatpno      And noticed that there where a lot of connections in TIME_WAIT...around 300+. So we tried applying some of the recommendations in this page particularly that of TCP_FIN_TIMEOUT, TCP_KEEPALIVE_INTERVAL & TCP_KEEPALIVE_PROBES. The connections in TIME_WAIT went lower but still fluctuates between 220 to 280(maybe due to the fact that a new connection is added from time to time and other connections in TIME_WAIT is not yet "timed-out"). Perhaps we could try adding TCP_TW_RECYCLE & TCP_TW_REUSE later when we don't see any improvement. Now going back to my main question: is there a solid evidence that a lot of TIME_WAIT'ed connections eat up a lot of RAM? Thanks in advance.


title: Create ssh user which can only access home directory

text: I read documentation on the internet on how to create a new user with SSH access. I figured it out and to create a user is quite simple. The next step I want to take is to jail this ssh server to the `/home/` directory on my machine. It needs the permission to write/create folder/files in directories of other users (CMS system). How can I implement this?


title: Using an incrementing variable in a bash command line for loop?

text: I'm using a bash commandline for-loop to concat a group of files together, and I'd like to append an incrementing digit. Something like this:               j=1;for i in *.bak; do echo {$j++: >> files.grp;cat $i >> files.grp; echo }, >> files.grp; done      So the output would like this:               {1:"file1 contents"},{2:"file2 contents"},


title: How to install/default to the command line version of Emacs?

text: I installed Emacs using `sudo apt-get install emacs`. The problem is that when I launch Emacs from the command line (e.g. `emacs main.c`) it opens Emacs with a GUI. I prefer the command line version which runs in the terminal emulator. How can I install (or change some default) so that Emacs will open in the command line instead of a GUI?


title: Recursively Gziping Files (and keep original files) & Gziping Text Input

text: I need Gzip to pre-zip some static files for a webserver I'm building. All of the files I need to gzip will be in a folder named `.cache`. Since some clients may not accept responses that are gzipped, I would like to keep all of the original files when I gzip them. Is there any command I can use to recursively gzip the files in my `.cache` folder while still keeping the original files? Will this command gzip gzipped files (ones that are postfixed with .gz already) if run on a folder with already gzipped files? While we're on the topic of gzip: I've been looking for a way to gzip text input passed to gzip instead of files. I came up with postfixing a dash on the command (like `gzip -c -`), but I'm not sure if that will work or how I use it. Can anyone explain?


title: Confusion about sed and '>'

text: The following command works fine:               sed s/input/raw_input/ p.py >p2.py && mv p2.py p.py      However, the following command turns p.py into an empty file:               sed s/input/raw_input/ p.py >p.py      The following also turns p.py into an empty file:               sed s/input/raw_input/ p.py | cat > p.py      Why don't the last two commands behave as expected? In particular why is p.py empty?


title: VIM - how to minimize tabindent on hilighted text

text: Right now, my VIM editor tab indent has some unusual behaviour. When I am in insert mode and press tab, the cursor indents about 3 spaces instead of a whole tab indent. **I like this**. When I high-light a block of text, then press `SHIFT` and `>` simultaneously, the block of text indents an entire tab indent instead of 3 spaces behaviour like above. **I do not like this**. How do I make the second action behave like the first action?


title: What is the correct name for the ">" command

text: I was trying to find how to pass some text to a file without overwriting what's there already using the `>` command and I realised I don't know what it's called. Searching for _right arrow_ or _right chevron_ or _more than_ command didn't show up anything. I've always just called it _pass to_.


title: Replacing/disabling plasma desktop/wallpaper?

text: I'm looking for a way to replace Plasma's wallpaper (desktop?) with Compiz's (or traditional). I'm running Compiz + Emerald as WM, and this disables the ability to have different activities on different virtual desktops at all, so this is the only way to have different wallpapers on each one. I noticed on Compiz's site, it suggests using wallpapercolor= 0,0,0,0 , but I'm running 4.8 and doubt this will work. I would switch to Gnome, as I had this working on it before, but I'm not a fan of Gnome3. Any help is appreciated.


title: List of error messages available for a command in Unix

text: Is it possible to find out what error messages a command includes? For example I want to see the list of error messages that `mkfs.ext3` command will print in different error situations. Shall I look into the source code or are there other ways to achieve this?


title: benchmark tools for linux

text: I have developed a software with perl language based on the Spread Toolkit wich is a network messages manager through the network(messages software through the network), now I have to stress my application and benchmark it, so being able to see the CPU and memory compsumption, etc... Could you recommend me any benchmark tool for linux? I have no idea about which software I could use, I can stress my app but dunno howto to see the system performance.