Linux is a free (libre), open source, Unix-like operating system.

learn more… | top users | synonyms

8
votes
3answers
217 views

Removing multiple slashes from path

I have been trying to write a sample code block to remove multiple backward or forward slashes from a path. E.g. //a//b should be /a/b; on windows c:\a\b\\c should be c:\a\b\c I am assuming that: ...
2
votes
2answers
43 views

Passing help options to a bash script

I used this code to give -h(help) options to my bash script. It's working fine and I wanted to get the code reviewed. ...
10
votes
2answers
156 views

mini-(Docker)-shell

I was given an assignment to write a mini-shell: To write your own shell, you will need to start with a C program that will prompt the user for input and accept in a number of arguments from a ...
4
votes
2answers
36 views

Parse a substring out of string, allocate memory accordingly

I have written the following code in order to: Find begin and end of FTP user and password from a given URL (ftp://[user[:password]@]host[:port]/url-path) Allocate ...
3
votes
2answers
56 views

Finding duplicate files using md5sum Unix command

This is an exercise from Think Python: How to Think Like a Computer Scientist Here's its description: In a large collection of MP3 files, there may be more than one copy of the same song, stored ...
1
vote
0answers
15 views

Parsing GTF file using command-line

I am extracting exons details from a GTF file using command line in Unix like cut, awk, grep or sed. input file.gtf: ...
5
votes
1answer
44 views

Bash function that allows running user aliases with sudo on Ubuntu

I wrote this little Bash function to replace my sudo command. It checks whether I have an alias for the given command and runs the aliased command instead of the ...
1
vote
1answer
16 views

Parse child value from XML using ezxml

I'm parsing an XML file and searching for a child value. As I'm familiar with this XML file structure, I know that the final value is a child of a child, and so I wrote the following code section: <...
2
votes
2answers
33 views

High CPU utilisation for Logs Manager shell script

I have written a shell script to manage the tcpdump pcap logs and syslog files in my Linux board, so as to maintain the disk usage to maximum of 70%. The script checks for the disk usage every ...
6
votes
2answers
80 views

CPU core temperature Unity indicator

Project now on Github: https://github.com/IanCaio/TempI I just finished a working version of a small Unity indicator in C, that is supposed to take the output of the application "sensors" (...
1
vote
1answer
18 views

Pausing script while waiting for Docker container and printing updates

I'm looking to improve it in brevity, readability, and simplicity. Basically, I'm just looking for a more elegant solution. What improvements can I make? ...
0
votes
1answer
52 views

Basic GNU/Linux C++ serial I/O class

I have wrote a small C++ class that provides some basic serial I/O functionality (it uses the standard GNU/Linux API). At this stage is working fine, before adding new functionality I want to get ...
1
vote
2answers
54 views

Iterating over a range of dates in a shell script

I have been working on a script that can be used to automatically pull the batch ids that were processed 4 days ago and which need to be processed tomorrow on the server. The batch IDs from 3 days ago ...
2
votes
0answers
39 views

Multithreaded C program to calculate CPU usage of cgroups

I am writing a program in an environment that makes use of cgroups to identify and group processes together. I want to parse the CPU utilization of each cgroup by sampling ...
4
votes
2answers
75 views

Simple program to read memory usage by PID in Linux

I just learn a little bit about C Programming and try to create a modular program so I created simple program to read memory usage by pid(s) in Linux. ...
3
votes
1answer
55 views

Automation of application utilities on Linux

I am working on a project to automate utilities of our application on Linux. The utilities are basically chunks of programs with specific options for specific tasks. They are run like UNIX commands. ...
1
vote
2answers
50 views

Hexdump utility in x86 NASM assembly

It's a simple hexdump that prints to stdout. I wanted to handle correctly input coming from the user typing at the terminal, this made the logic a little more complicated than just exiting after ...
6
votes
1answer
40 views

Extracting Linux configuration information using Bash and Perl

For few days I'm thinking about making my code faster and using less CPU. This code is a statusbar that runs in a loop. I'm asking because there's a lot of perl and I'm wondering if it could be done ...
4
votes
1answer
31 views

Yum Notification Script

This is a Bash script I wrote to email me when updates are available for my server. I'm new to bash programming, so I don't know if I've done this well. ...
5
votes
1answer
16 views

Script to record an inventory of a backup

This is a script designed to make an inventory file which records the contents of a directory allowing verification that a backup has the same data. The same script can also A full github repo is ...
14
votes
2answers
1k views

Tetris in C, in 200 lines

I aimed at making fully functional (real) Tetris, in the shortest way possible in C. The result is a terminal game for Linux, that uses ncurses. I made it for my friend, who wanted to play it on his ...
3
votes
1answer
37 views

File shredder in x86 NASM Assembly

This is a file shredder utility that runs on Linux. It writes random bytes over the file contents, repeating this 48 times and calling sys_fsync after each pass to ...
5
votes
1answer
36 views

Program to print all evironment variables

I'm learning x86 assembly on Linux and this is the first program I wrote, so I'm looking for all kinds of ways to improve it. ...
0
votes
0answers
27 views

Check the battery's charge level and emit an alert on low/high value

The following script check constantly the battery's charge level of the user's laptop via the acpi command. When such level reach a low/high value, the script will ...
5
votes
1answer
54 views

Brightness Web Server

This is the first real program I've written in Go so have at it! I wrote it because I use a tiling window manager that doesn't have any brightness control functionality (at least not that I know of). ...
4
votes
1answer
63 views

Raspberry Pi headless server using bash and USB automounting

Revised from: Bash scripts and udev rules to handle USB auto mounting / unmounting Tested: Uses USB insert/remove to control a headless Raspberry Pi 3 with Raspian Jessie Lite Changes: Implement ...
2
votes
1answer
69 views

Bash scripts and udev rules to handle USB auto mounting / unmounting

Very new to Raspberry Pi and bash, but working on a headless server that will run a streaming app from USB audio card. The plan is to take a USB card with settings file, and when inserted, the usb ...
5
votes
3answers
695 views

Snake game in C for Linux console

Please help me improve this code. Move snake using : a w s d. (My compiler doesn't support initialization of index variables inside loops, so please ignore this part) ...
8
votes
1answer
95 views

Baby-sitting bash script using DVD drive

This is the script I wrote to make an automated POC baby-sitter in 5 lines. I first found this on a GIF or meme site and thought of making a POC script that does the same. ...
8
votes
2answers
132 views

Thread to send heartbeat UDP packets

This C code will run on an embedded machine with a Linux OS. It should create data packets (ASCII) to repeatedly be sent to a UDP server. Just to give an overview about what functions should do: <...
5
votes
2answers
91 views

Thread synchronization with mutex

This program prints odd numbers by thread1 and even numbers by thread2 sequentially. Can this code be optimized or made more ...
1
vote
1answer
53 views
5
votes
1answer
45 views

Bash script for xrandr modification

Simply, I call the script (brightness.sh) and pass a three character value as an argument. I've got commands to strip individual numbers for math processes, and then the final commands to apply the ...
3
votes
1answer
68 views

Template for PHP service (/etc/init.d) script

I wanted a template for a service script that is versatile and easily configurable. Along with producing similar outputs to the SSH and Samba daemons, I request the code to be as clean, simple and ...
4
votes
1answer
41 views

Simple shell script to backup to Amazon over iSCSI

The script works but I know that it can be improved. Please note that my scripting skills are very basic :) (as it can be seen in my Frankenstein script – I took bits and pieces of the code from ...
4
votes
1answer
58 views

Bash script to determine a distro, update, upgrade and install the apps I use

This is my first bash script. I am trying to learn scripting and needed an idea. This is the first idea I came up with. When I used to distro hop I had to reinstall everything. This helped me out once ...
4
votes
1answer
71 views

Watch log dir for new file, automatically tail to slack

We have a process that outputs to log files in the format /var/log/xxx/YYYY_MM_DD.log - the file name is chosen programmatically and is not rotated using logrotate ...
0
votes
0answers
52 views

Resolving the path to a Bash script

I wrote a function to resolve the full path to the current Bash script, and I'm wondering if it's SOLID: ...
-1
votes
1answer
70 views

Measuring execution time of a simple operation

The purpose of the following code is to measure the execution time of a simple operation (1+1) and of a call to a function who does nothing (foo). The code ...
5
votes
1answer
53 views

Bash script to open or close gnome-terminal with a single keybinding

I wanted to bind a single hot key to open and close gnome-terminal in a way similar to terminal emulators such as tilda or guake. I use Ubuntu, and have configured this script to be executed when I ...
3
votes
2answers
57 views

Nagios plugin webdav check 2

Original post: nagios plugin webdav check According to the good advice I have received I've made some modifications to the code: ...
3
votes
2answers
94 views

nagios plugin webdav check

I have written a small plugin for nagios to check a WebDAV server. It is supposed to connect using a username and password and upload & delete a test file This is my code: ...
2
votes
2answers
64 views

Linux C Port Knock Implementation

Compile with: gcc -std=gnu11 -o "portknock" "portknock.c" -lpcap I did this as a learning experience, and it actually ended up being something useful. I made a ...
5
votes
0answers
229 views

Automated owncloud installation script

Here is a shell script which installs and configure owncloud on a Debian server. It also installs apache2 and MySQL as dependencies and fail2ban with a specific rule for owncloud. Apache2 is also ...
4
votes
1answer
161 views

Parsing a string to extract values

I am writing some C# that will be running on Linux and will extract values from a kernel generated system file that represents readings from a sensor. The file contains two lines of text, and I have ...
3
votes
2answers
117 views

Basic shell implementation

Here is a small project to implement a basic shell. It is a personal ongoing project to keep system call usage fresh. It currently does background processes and some basic signal handling. I am ...
5
votes
2answers
287 views

Cleanup and server restart script

I have written a simple script for managing our Tomcat and Apache instances for deployment. What this script basically does is, when called, it copies the ROOT.war ...
3
votes
2answers
84 views

Dockerfile to install Apache

I'm getting started with Docker, and I've set up a very simple image built from a Dockerfile. It's based FROM the ubuntu image, ...
5
votes
1answer
100 views

Constructing a simple shell from scratch

I'm actually doing my whole shell in C from scratch from a Linux computer. The thing is that I think we all do our best from creating the simplest things that can be explained easily. And I'm not sure ...
5
votes
1answer
61 views

Function to get specified key from /proc/cpuinfo

On Linux, the file /proc/cpuinfo returns a set of key-value pairs, where the key and value are separated by a colon and each pair has its own line. It's a bit more ...